Skip to content

Commit

Permalink
refactor(net/ghttp): rename user request and response types for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
hailaz committed Mar 5, 2025
1 parent e2ad0a5 commit c12be86
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions net/ghttp/ghttp_z_unit_feature_request_param_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,34 @@ import (
"github.com/gogf/gf/v2/util/guid"
)

type UserReq struct {
type UserTagInReq struct {
g.Meta `path:"/user" tags:"User" method:"post" summary:"user api" title:"api title"`
Id int `v:"required" d:"1"`
Name string `v:"required" in:"cookie"`
Age string `v:"required" in:"header"`
// header,query,cookie,form
// struct tag in:header,query,cookie,form
}

type UserRes struct {
type UserTagInRes struct {
g.Meta `mime:"text/html" example:"string"`
}

var (
User = cUser{}
UserTagIn = cUserTagIn{}
)

type cUser struct{}
type cUserTagIn struct{}

func (c *cUser) User(ctx context.Context, req *UserReq) (res *UserRes, err error) {
func (c *cUserTagIn) User(ctx context.Context, req *UserTagInReq) (res *UserTagInRes, err error) {
g.RequestFromCtx(ctx).Response.WriteJson(req)
return
}

func Test_Params_Tag(t *testing.T) {
func Test_ParamsTagIn(t *testing.T) {
s := g.Server(guid.S())
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(ghttp.MiddlewareHandlerResponse)
group.Bind(User)
group.Bind(UserTagIn)
})
s.SetDumpRouterMap(false)
s.Start()
Expand All @@ -60,13 +60,13 @@ func Test_Params_Tag(t *testing.T) {
})
}

func Benchmark_ParamTag(b *testing.B) {
func Benchmark_ParamTagIn(b *testing.B) {
b.StopTimer()

s := g.Server(guid.S())
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(ghttp.MiddlewareHandlerResponse)
group.Bind(User)
group.Bind(UserTagIn)
})
s.SetDumpRouterMap(false)
s.SetAccessLogEnabled(false)
Expand Down

0 comments on commit c12be86

Please sign in to comment.