mirror of
https://gitee.com/johng/gf
synced 2026-06-14 13:01:01 +08:00
improve package goai; add example for array items response definition
This commit is contained in:
33
example/httpserver/response_with_json_array/controller.go
Normal file
33
example/httpserver/response_with_json_array/controller.go
Normal file
@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
type Req struct {
|
||||
g.Meta `path:"/user" method:"get"`
|
||||
}
|
||||
type Res []Item
|
||||
|
||||
type Item struct {
|
||||
Id int64
|
||||
Name string
|
||||
}
|
||||
|
||||
var (
|
||||
User = cUser{}
|
||||
)
|
||||
|
||||
type cUser struct{}
|
||||
|
||||
func (c *cUser) GetList(ctx context.Context, req *Req) (res *Res, err error) {
|
||||
res = &Res{
|
||||
{Id: 1, Name: "john"},
|
||||
{Id: 2, Name: "smith"},
|
||||
{Id: 3, Name: "alice"},
|
||||
{Id: 4, Name: "katyusha"},
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user