Files
gf/example/httpserver/swagger/main.go

50 lines
1.0 KiB
Go
Raw Normal View History

// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
2022-03-01 11:43:42 +08:00
package main
import (
"context"
"fmt"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
)
// HelloReq hello request
2022-03-01 11:43:42 +08:00
type HelloReq struct {
2022-03-24 21:56:37 +08:00
g.Meta `path:"/hello" method:"get" sort:"1"`
2022-03-01 11:43:42 +08:00
Name string `v:"required" dc:"Your name"`
}
// HelloRes hello response
2022-03-01 11:43:42 +08:00
type HelloRes struct {
Reply string `dc:"Reply content"`
}
// Hello Controller
2022-03-01 11:43:42 +08:00
type Hello struct{}
// Say function
2022-03-01 11:43:42 +08:00
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()
}