Files
gf/example/httpserver/default_value/main.go
John Guo 12e9febe9e fix issue #2516 (#2531)
* fix issue #2516

* golang ci configuration updates

* add example for default value of http request
2023-03-22 20:14:57 +08:00

42 lines
1008 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
)
type GetListReq struct {
g.Meta `path:"/" method:"get"`
Type string `v:"required#请选择内容模型" dc:"内容模型"`
Page int `v:"min:0#分页号码错误" dc:"分页号码" d:"1"`
Size int `v:"max:50#分页数量最大50条" dc:"分页数量最大50" d:"10"`
Sort int `v:"in:0,1,2#排序类型不合法" dc:"排序类型(0:最新, 默认。1:活跃, 2:热度)"`
}
type GetListRes struct {
Items []Item `dc:"内容列表"`
}
type Item struct {
Id int64 `dc:"内容ID"`
Title string `dc:"内容标题"`
}
type Controller struct{}
func (Controller) GetList(ctx context.Context, req *GetListReq) (res *GetListRes, err error) {
g.Log().Info(ctx, req)
return
}
func main() {
s := g.Server()
s.Group("/content", func(group *ghttp.RouterGroup) {
group.Middleware(ghttp.MiddlewareHandlerResponse)
group.Bind(&Controller{})
})
s.SetPort(8199)
s.Run()
}