-
Notifications
You must be signed in to change notification settings - Fork 742
/
config.go
72 lines (62 loc) · 1.42 KB
/
config.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
package pubstack
import (
"encoding/json"
"net/http"
"net/url"
"time"
"github.com/docker/go-units"
)
func fetchConfig(client *http.Client, endpoint *url.URL) (*Configuration, error) {
res, err := client.Get(endpoint.String())
if err != nil {
return nil, err
}
defer res.Body.Close()
c := Configuration{}
err = json.NewDecoder(res.Body).Decode(&c)
if err != nil {
return nil, err
}
return &c, nil
}
func newBufferConfig(count int, size, duration string) (*bufferConfig, error) {
pDuration, err := time.ParseDuration(duration)
if err != nil {
return nil, err
}
pSize, err := units.FromHumanSize(size)
if err != nil {
return nil, err
}
return &bufferConfig{
pDuration,
int64(count),
pSize,
}, nil
}
func (a *Configuration) isSameAs(b *Configuration) bool {
sameEndpoint := a.Endpoint == b.Endpoint
sameScopeID := a.ScopeID == b.ScopeID
sameFeature := len(a.Features) == len(b.Features)
for key := range a.Features {
sameFeature = sameFeature && a.Features[key] == b.Features[key]
}
return sameFeature && sameEndpoint && sameScopeID
}
func (a *Configuration) clone() *Configuration {
c := &Configuration{
ScopeID: a.ScopeID,
Endpoint: a.Endpoint,
Features: make(map[string]bool, len(a.Features)),
}
for k, v := range a.Features {
c.Features[k] = v
}
return c
}
func (a *Configuration) disableAllFeatures() *Configuration {
for k := range a.Features {
a.Features[k] = false
}
return a
}