-
Notifications
You must be signed in to change notification settings - Fork 652
/
Copy pathapi.go
60 lines (49 loc) · 1.1 KB
/
api.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
package page
import (
"github.com/yaoapp/yao/share"
)
// SetupAPIs 设定API数据
func (page *Page) SetupAPIs() {
defaults := map[string]share.API{
"data": apiDataDefault(),
"setting": apiSettingDefault(),
}
// 开发者填写的规则
for name := range page.APIs {
if _, has := defaults[name]; !has {
delete(page.APIs, name)
continue
}
api := defaults[name]
api.Name = name
if page.APIs[name].Process != "" {
api.Process = page.APIs[name].Process
}
if page.APIs[name].Guard != "" {
api.Guard = page.APIs[name].Guard
}
if page.APIs[name].Default != nil {
api.Default = page.APIs[name].Default
}
defaults[name] = api
}
page.APIs = defaults
}
// apiSearchDefault data 接口默认值
func apiDataDefault() share.API {
param := map[string]interface{}{}
return share.API{
Name: "data",
Guard: "bearer-jwt",
Process: "xiang.page.data",
Default: []interface{}{param},
}
}
// apiSettingDefault setting 接口默认值
func apiSettingDefault() share.API {
return share.API{
Name: "setting",
Guard: "bearer-jwt",
Process: "xiang.page.setting",
}
}