-
Notifications
You must be signed in to change notification settings - Fork 706
/
config.go
51 lines (45 loc) · 1.06 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
package pubstack
import (
"encoding/json"
"github.com/docker/go-units"
"net/http"
"net/url"
"time"
)
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
}