api swagger ui update

This commit is contained in:
John Guo
2022-03-01 11:43:42 +08:00
parent 308e13a546
commit 88a9eef8a6
11 changed files with 104 additions and 26 deletions

View File

@ -0,0 +1,4 @@
server:
address: ":8199"
openapiPath: "/api.json"
swaggerPath: "/swagger"

View File

@ -0,0 +1,38 @@
package main
import (
"context"
"fmt"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
)
type HelloReq struct {
g.Meta `path:"/hello" method:"get"`
Name string `v:"required" dc:"Your name"`
}
type HelloRes struct {
Reply string `dc:"Reply content"`
}
type Hello struct{}
func (Hello) Say(ctx context.Context, req *HelloReq) (res *HelloRes, err error) {
g.Log().Debugf(ctx, `receive say: %+v`, req)
res = &HelloRes{
Reply: fmt.Sprintf(`Hi %s`, req.Name),
}
return
}
func main() {
s := g.Server()
s.Use(ghttp.MiddlewareHandlerResponse)
s.Group("/", func(group *ghttp.RouterGroup) {
group.Bind(
new(Hello),
)
})
s.Run()
}