This commit is contained in:
John Guo
2021-10-13 22:28:49 +08:00
parent f887c9f44b
commit 920c97af79
14 changed files with 91 additions and 39 deletions

View File

@ -0,0 +1,33 @@
package main
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
)
type HelloReq struct {
g.Meta `path:"/hello" tags:"Test" method:"get" description:"Hello world handler for test"`
Content string `json:"content" in:"query"`
}
type HelloRes struct {
Content string `json:"content" description:"Hello response content for test"`
}
// Hello is an example handler.
func Hello(ctx context.Context, req *HelloReq) (res *HelloRes, err error) {
return &HelloRes{Content: req.Content}, nil
}
func main() {
s := g.Server()
s.Use(
ghttp.MiddlewareHandlerResponse,
)
s.BindHandler("/hello", Hello)
s.SetOpenApiPath("/api.json")
s.SetSwaggerPath("/swagger")
s.SetPort(8199)
s.Run()
}