坐标: https://github.com/1-st/gin-annotation
```go
/* Hello a simple controller
[
method:GET,
groups:/api,
path:/hello-world,
need:auth
]
*/
func HelloWorld(ctx *gin.Context) {
ctx.JSON( http.StatusOK, map[string]string{
"msg": "hello, world",
})
}
```
思路:读取 Go 源代码的 AST 文件,然后生成一个 route.entry.go 路由文件,像这样:
```go
import (
"gin-annotation/_example/simple/controller"
"gin-annotation/_example/simple/middleware"
"github.com/gin-gonic/gin"
)
func Route(e *gin.Engine) {
api := e.Group("/api", middleware.Log)
{
v1 := api.Group("/v1")
{
v1.GET("/hello-world", middleware.Auth, controller.HelloWorld)
}
}
}
```
如果觉得有用 /有趣请 star,谢谢!
有疑问加站长微信联系(非本文作者))