-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.go
52 lines (38 loc) · 902 Bytes
/
cli.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
package cli
import "context"
// CLI ... [inject:"#cli"]
type CLI interface {
// 取客户端
GetClient() Client
// 取服务端
GetServer() Server
// 把这个 CLI 绑定到指定的 Context
Bind(cc context.Context) context.Context
}
// New 初始化 cli 模块
func New(cfg *Configuration) CLI {
cfg = prepareConfig(cfg)
ctx, err := cfg.ContextFactory.NewContext(cfg)
if err != nil {
panic(err)
}
return ctx.CLI
}
////////////////////////////////////////////////////////////////////////////////
func prepareConfig(c *Configuration) *Configuration {
if c == nil {
c = &Configuration{}
}
if c.ContextFactory == nil {
c.ContextFactory = &DefaultContextFactory{}
}
if c.ClientFactory == nil {
c.ClientFactory = &DefaultClientFactory{}
}
if c.ServerFactory == nil {
c.ServerFactory = &DefaultServerFactory{}
}
// c.Handlers = nil
// c.Filters = nil
return c
}