Zgin is a API framework written in Go (Golang). An MVCS, Restful, and version control framework based on the Gin framework. If you need performance and good productivity, you will love zgin.
To install zgin package, you need to install Go and set your Go workspace first.
- The first need Go installed (version 1.11+ is required), then you can use the below Go command to install zgin.
$ go get -u github.com/ZYallers/zgin
- Import it in your code:
import "github.com/ZYallers/zgin"
package main
import (
"fmt"
"github.com/ZYallers/zgin"
"github.com/ZYallers/zgin/consts"
"github.com/ZYallers/zgin/example/route"
"github.com/ZYallers/zgin/handler"
"github.com/ZYallers/zgin/helper/config"
"github.com/ZYallers/zgin/middleware"
"github.com/ZYallers/zgin/option"
"github.com/gin-gonic/gin"
)
func main() {
gin.DisableConsoleColor()
gin.DebugPrintRouteFunc = func(httpMethod, absolutePath, handlerName string, nuHandlers int) {}
if err := config.ReadFile(); err != nil {
panic(fmt.Errorf("read config file error: %s", err))
}
app := zgin.New(
option.WithMode(consts.DevMode),
)
app.Run(
handler.WithNoRoute(),
handler.WithHealth(),
middleware.WithZapRecovery(),
middleware.WithZapLogger(),
handler.WithExpVar(),
handler.WithPrometheus(),
handler.WithSwagger(),
handler.WithPProf(),
middleware.WithRestCheck(route.Restful),
)
}
run main.go and visit http://0.0.0.0:9010/health (for windows "http://localhost:8080/health") on browser
$ go run main.go
- MVCS four-tier architecture support
- Restful interface style support
- API version control and permission custom configuration
- PProf middleware support
- Prometheus middleware support
- Swagger api docs middleware support
- Graceful server shutdown and reload
Zgin uses encoding/json as default json package but you can change to jsoniter by build from other tags.
$ go build -tags=jsoniter .
Released under the MIT License