examples/httpserver/response-json-array #292
Replies: 1 comment
-
// Req defines the request structure for the user endpoint.
// It uses GoFrame's metadata to specify the endpoint path and HTTP method.
type Req struct {
g.Meta `path:"/user" method:"get"`
}
// Res defines the response structure as a slice of Item.
// This will be serialized as a JSON array in the response.
type Res []Item
// Item represents a single user item in the response array.
// Each field will be properly serialized in the JSON response.
type Item struct {
Id int64 `json:"id" dc:"User ID"`
Name string `json:"name" dc:"User name"`
}
// User is the controller structure for handling user-related requests.
type User struct{}
// GetList handles the user list endpoint request.
// It returns a list of users as a JSON array.
func (User) GetList(ctx context.Context, req *Req) (res *Res, err error) {
res = &Res{
{Id: 1, Name: "john"},
{Id: 2, Name: "smith"},
{Id: 3, Name: "alice"},
}
return
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
examples/httpserver/response-json-array
使用 GoFrame 框架处理 HTTP 服务器的 JSON 数组响应
https://goframe.org/examples/httpserver/response-json-array
Beta Was this translation helpful? Give feedback.
All reactions