Skip to content

Commit

Permalink
fix issue #2457 (#3297)
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn authored Feb 2, 2024
1 parent ef2b47d commit cc79d23
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions net/ghttp/ghttp_z_unit_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,3 +474,53 @@ func Test_Issue3077(t *testing.T) {
t.Assert(c.GetContent(ctx, "/echo?"), `&{{} a }`)
})
}

type ListMessageReq struct {
g.Meta `path:"/list" method:"get"`
StartTime int64
EndTime int64
}
type ListMessageRes struct {
g.Meta
Title string
Content string
}
type BaseRes[T any] struct {
g.Meta
Code int
Data T
Msg string
}
type cMessage struct{}

func (c *cMessage) List(ctx context.Context, req *ListMessageReq) (res *BaseRes[*ListMessageRes], err error) {
res = &BaseRes[*ListMessageRes]{
Code: 100,
Data: &ListMessageRes{
Title: "title",
Content: "hello",
},
}
return res, err
}

// https://github.com/gogf/gf/issues/2457
func Test_Issue2457(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
s := g.Server(guid.S())
s.Use(ghttp.MiddlewareHandlerResponse)
s.Group("/", func(group *ghttp.RouterGroup) {
group.Bind(
new(cMessage),
)
})
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)

c := g.Client()
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(c.GetContent(ctx, "/list"), `{"code":0,"message":"","data":{"Code":100,"Data":{"Title":"title","Content":"hello"},"Msg":""}}`)
})
}

0 comments on commit cc79d23

Please # to comment.