-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
86 lines (73 loc) · 1.6 KB
/
options.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
79
80
81
82
83
84
85
86
package acm
import (
"fmt"
)
// apiPath API相对路径
type apiPath string
func (ap apiPath) URL(host string, port uint16) string {
return fmt.Sprintf("http://%s:%d/%s", host, port, ap)
}
const (
getServer apiPath = "diamond-server/diamond"
getConfig apiPath = "diamond-server/config.co"
setConfig apiPath = "diamond-server/basestone.do?method=syncUpdateAll"
delConfig apiPath = "diamond-server/datum.do?method=deleteAllDatums"
)
// authCreds 鉴权凭证
type authCreds struct {
accessKey string
secretKey string
}
func (ac *authCreds) check() {
if ac.accessKey == "" {
panic("aliacm: access key is required")
} else if ac.secretKey == "" {
panic("aliacm: secret key is required")
}
}
// Options ACM客户端配置
type Options struct {
endpoint string
namespace string
groupName string
authCreds authCreds
}
type Option func(options *Options)
func newOptions(fns []Option) Options {
opts := Options{
groupName: "DEFAULT_GROUP",
}
for _, fn := range fns {
fn(&opts)
}
if opts.endpoint == "" {
panic("aliacm: endpoint is required")
} else if opts.namespace == "" {
panic("aliacm: namespace is required")
}
opts.authCreds.check()
return opts
}
func Endpoint(ep string) Option {
return func(options *Options) {
options.endpoint = ep
}
}
func Namespace(ns string) Option {
return func(options *Options) {
options.namespace = ns
}
}
func GroupName(gn string) Option {
return func(options *Options) {
options.groupName = gn
}
}
func AuthCreds(ak, sk string) Option {
return func(options *Options) {
options.authCreds = authCreds{
accessKey: ak,
secretKey: sk,
}
}
}