mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
api swagger ui update
This commit is contained in:
4
example/httpserver/swagger/config.yaml
Normal file
4
example/httpserver/swagger/config.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
server:
|
||||
address: ":8199"
|
||||
openapiPath: "/api.json"
|
||||
swaggerPath: "/swagger"
|
||||
38
example/httpserver/swagger/main.go
Normal file
38
example/httpserver/swagger/main.go
Normal 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()
|
||||
}
|
||||
Reference in New Issue
Block a user