/
z_test.go
78 lines (68 loc) · 1.49 KB
/
z_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package docs_test
import (
"path/filepath"
"testing"
"time"
"github.com/lovego/fs"
"github.com/lovego/goa"
)
func TestExampleGroup(t *testing.T) {
router := goa.New()
router.DocDir(filepath.Join(fs.SourceDir(), "testdata"))
accounts := router.Group("/", "账号", "用户、公司、员工、角色、权限")
accounts.Child("/users", "用户").
Get(`/`, testHandler).
Get(`/(?P<type>\w+)/(?P<id>\d+)`, testHandler2)
//accounts.Group("/companies", "公司")
//router.Group("/goods", "商品")
//router.Group("/bill", "单据", "采购、销售")
//router.Group("/storage", "库存")
// Output:
}
type T struct {
Type string `c:"类型"`
Id *int `c:"ID"`
Flag bool `json:"-" c:"标志"`
}
func testHandler(req struct {
Title string `用户列表`
Desc string `列出所有的用户`
Query struct {
Page int `c:"页码"`
T
}
Header struct {
Cookie string `c:"Cookie中包含会话信息"`
}
Body *struct {
Name *string `c:"名称"`
T
}
Session struct {
UserId int64
LoginAt time.Time
}
Ctx *goa.Context
}, resp *struct {
Data []*struct {
Id *int `c:"ID"`
Name *string `c:"名称"`
}
Error error
}) {
}
func testHandler2(req struct {
Title string `用户详情`
Desc string `获取用户的详细信息`
Param T `c:"type: 用户类型,\\id:用户ID"`
}, resp *struct {
Header struct {
SetCookie string `header:"Set-Cookie" c:"返回登录会话"`
}
Data struct {
Id int `c:"ID"`
Name string `c:"名称"`
}
Error error
}) {
}