forked from glennliao/apijson-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapijson.go
More file actions
54 lines (42 loc) · 908 Bytes
/
apijson.go
File metadata and controls
54 lines (42 loc) · 908 Bytes
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
package apijson
import (
"context"
"github.com/glennliao/apijson-go/config"
)
type Plugin interface {
Install(ctx context.Context, a *ApiJson)
}
type ApiJson struct {
config *config.Config
Debug bool // 是否开启debug模式, 显示每步骤
ctx context.Context
}
var DefaultApiJson = New()
type App struct {
}
func New() *ApiJson {
a := &ApiJson{}
a.config = config.New()
a.ctx = context.Background()
return a
}
// Load load for defaultApiJson, 简化使用
func Load(apps ...func(ctx context.Context, a *ApiJson)) *ApiJson {
for _, app := range apps {
DefaultApiJson.Use(app)
}
DefaultApiJson.Load()
return DefaultApiJson
}
func (a *ApiJson) Use(p ...func(ctx context.Context, a *ApiJson)) *ApiJson {
for _, plugin := range p {
plugin(a.ctx, a)
}
return a
}
func (a *ApiJson) Load() {
a.config.Load()
}
func (a *ApiJson) Config() *config.Config {
return a.config
}