All Projects → philchia → Zen

philchia / Zen

Licence: mit
zen is a elegant and lightweight web framework for Go

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Zen

Iris
The fastest HTTP/2 Go Web Framework. AWS Lambda, gRPC, MVC, Unique Router, Websockets, Sessions, Test suite, Dependency Injection and more. A true successor of expressjs and laravel | 谢谢 https://github.com/kataras/iris/issues/1329 |
Stars: ✭ 21,587 (+8299.61%)
Mutual labels:  middleware, framework, router, mvc
Pure Http
✨ The simple web framework for Node.js with zero dependencies.
Stars: ✭ 139 (-45.91%)
Mutual labels:  middleware, framework, router
Foxify
The fast, easy to use & typescript ready web framework for Node.js
Stars: ✭ 138 (-46.3%)
Mutual labels:  middleware, framework, router
Gin
Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.
Stars: ✭ 53,971 (+20900.39%)
Mutual labels:  middleware, framework, router
Diet
A tiny, fast and modular node.js web framework. Good for making fast & scalable apps and apis.
Stars: ✭ 394 (+53.31%)
Mutual labels:  middleware, router, mvc
Min
A minimalistic web framework with route grouping and middleware chaining
Stars: ✭ 95 (-63.04%)
Mutual labels:  middleware, framework, router
Wpemerge
A modern, MVC-powered WordPress as a CMS workflow. 🚀
Stars: ✭ 348 (+35.41%)
Mutual labels:  middleware, framework, mvc
Golf
⛳️ The Golf web framework
Stars: ✭ 248 (-3.5%)
Mutual labels:  middleware, framework, router
Gear
A lightweight, composable and high performance web service framework for Go.
Stars: ✭ 544 (+111.67%)
Mutual labels:  middleware, framework, router
Dragon
⚡A powerful HTTP router and URL matcher for building Deno web servers.
Stars: ✭ 56 (-78.21%)
Mutual labels:  middleware, framework, router
Twig
Twig - less is more's web server for golang
Stars: ✭ 98 (-61.87%)
Mutual labels:  middleware, framework, router
Typin
Declarative framework for interactive CLI applications
Stars: ✭ 126 (-50.97%)
Mutual labels:  middleware, framework
Goat
[DEPRECATED] 🐐 A minimalistic JSON API server in Go
Stars: ✭ 161 (-37.35%)
Mutual labels:  middleware, framework
Rayo.js
Micro framework for Node.js
Stars: ✭ 170 (-33.85%)
Mutual labels:  middleware, router
Webgo
A minimal framework to build web apps; with handler chaining, middleware support; and most of all standard library compliant HTTP handlers(i.e. http.HandlerFunc).
Stars: ✭ 165 (-35.8%)
Mutual labels:  middleware, router
Http Router
🎉 Release 2.0 is released! Very fast HTTP router for PHP 7.1+ (incl. PHP8 with attributes) based on PSR-7 and PSR-15 with support for annotations and OpenApi (Swagger)
Stars: ✭ 124 (-51.75%)
Mutual labels:  middleware, router
Middy
🛵 The stylish Node.js middleware engine for AWS Lambda
Stars: ✭ 2,592 (+908.56%)
Mutual labels:  middleware, framework
Ego
Ego is a full-stack web framework written in Go, lightweight and efficient front-end component solutions, based on gin. The front-end is compiled, does not affect the back-end.
Stars: ✭ 185 (-28.02%)
Mutual labels:  middleware, framework
Routerify
A lightweight, idiomatic, composable and modular router implementation with middleware support for the Rust HTTP library hyper.rs
Stars: ✭ 173 (-32.68%)
Mutual labels:  middleware, router
Mux
A powerful HTTP router and URL matcher for building Go web servers with 🦍
Stars: ✭ 15,667 (+5996.11%)
Mutual labels:  middleware, router

zen is a lightweight go framework for web development CircleCI

Coverage Status Go Report Card golang GoDoc license

zen is a web framework written by go, you will love it if you preffer high performance and lightweight!!!

Features

  • High performance HTTP router
  • Restful API
  • Parameters in path
  • Group APIs
  • Structure log support
  • Form validate and struct bind
  • JSON and XML data bind
  • Built in panic handler
  • Middleware at root or group level
  • Handy response functions
  • Context support
  • Graceful shutdown

Installation

go get github.com/philchia/zen

Examples

Start a server

func main() {
    server := zen.New()

    if err := server.Run(":8080"); err != nil {
        log.Println(err)
    }
}

Using GET, POST, PUT, PATCH, DELETE

    server := zen.New()
    server.Get("/test",handler)
    server.Post("/test", handler)
    server.Put("/test",handler)
    server.Patch("/test", handler)
    server.Delete("/test",handler)

Group route

    server := zen.New()

    user := server.Group("/user")
    {
        user.Get("/test",handler)
        user.Post("/test", handler)
        user.Put("/test",handler)
        user.Patch("/test", handler)
        user.Delete("/test",handler)
    }

Add a middleware

    server := zen.New()
    server.AddInterceptor(func(h HandlerFunc) HandlerFunc {
        return func(ctx zen.Context) {
            ctx.SetField("REQID",1)
            ctx.LogInfo("Root Middleware")
            h(ctx)
        }
    })

Group layer middleware

    server := zen.New()

    user := server.Group("/user")
    {
        user.AddInterceptor(func(h HandlerFunc) HandlerFunc {
        return func(ctx zen.Context) {
            ctx.LogInfo("Group Middleware")
            h(ctx)
        }
    })
    }

Parameters in path

    server := zen.New()
    server.Get("/user/:uid",func (ctx zen.Context) {
        ctx.JSON(map[string]string{"uid": ctx.Param("uid")})
    })
    if err := server.Run(":8080"); err != nil {
    log.Println(err)
    }

Parse and validate input

func handler(ctx zen.Context) {
    var input struct {
        Name string `form:"name" json:"name"`
        Age  int    `form:"age" json:"age"`
        Mail string `form:"mail" valid:"[A-Z0-9a-z._%+-][email protected][A-Za-z0-9.-]+\\.[A-Za-z]{2,64}" msg:"Illegal email" json:"mail"`
    }

    if err := ctx.ParseValidForm(&input); err != nil {
        ctx.JSON(map[string]string{"err": err.Error()})
        return
    }
    log.Println(input)
    ctx.JSON(input)
}

Handle 404

    server := zen.New()
    server.HandleNotFound(func(ctx zen.Context) {
        ctx.WriteStatus(StatusNotFound)
        ctx.WriteString(StatusText(StatusNotFound))
    })
    if err := server.Run(":8080"); err != nil {
    log.Println(err)
    }

Context support

    server := zen.New()
    server.HandleNotFound(func(ctx zen.Context) {
        ctx, cancel := ctx.WithDeadline(time.Now().Add(time.Second) * 3)
        defer cancel()
        db, _ := sql.Open("mysql", "dsn")
        db.QueryContext(ctx, "SELECT * FROM table;")
    })
    if err := server.Run(":8080"); err != nil {
    log.Println(err)
    }

Standard http.HandleFunc support

    server := zen.New()
    server.Get("/user/:uid",zen.WrapF(func(rw http.ResponseWriter, req *http.Request) {

    }))
    if err := server.Run(":8080"); err != nil {
    log.Println(err)
    }

Graceful shutdown

    server := zen.New()
    server.ShutdownDuration = time.Second * 10
    server.Shutdown()

Force close

    server := zen.New()
    server.Close()

License

zen is published under MIT license

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].