github.com/prebid/prebid-server/v2@v2.18.0/analytics/pubstack/config.go (about) 1 package pubstack 2 3 import ( 4 "encoding/json" 5 "net/http" 6 "net/url" 7 "time" 8 9 "github.com/docker/go-units" 10 ) 11 12 func fetchConfig(client *http.Client, endpoint *url.URL) (*Configuration, error) { 13 res, err := client.Get(endpoint.String()) 14 if err != nil { 15 return nil, err 16 } 17 18 defer res.Body.Close() 19 c := Configuration{} 20 err = json.NewDecoder(res.Body).Decode(&c) 21 if err != nil { 22 return nil, err 23 } 24 return &c, nil 25 } 26 27 func newBufferConfig(count int, size, duration string) (*bufferConfig, error) { 28 pDuration, err := time.ParseDuration(duration) 29 if err != nil { 30 return nil, err 31 } 32 pSize, err := units.FromHumanSize(size) 33 if err != nil { 34 return nil, err 35 } 36 return &bufferConfig{ 37 pDuration, 38 int64(count), 39 pSize, 40 }, nil 41 } 42 43 func (a *Configuration) isSameAs(b *Configuration) bool { 44 sameEndpoint := a.Endpoint == b.Endpoint 45 sameScopeID := a.ScopeID == b.ScopeID 46 sameFeature := len(a.Features) == len(b.Features) 47 for key := range a.Features { 48 sameFeature = sameFeature && a.Features[key] == b.Features[key] 49 } 50 return sameFeature && sameEndpoint && sameScopeID 51 } 52 53 func (a *Configuration) clone() *Configuration { 54 c := &Configuration{ 55 ScopeID: a.ScopeID, 56 Endpoint: a.Endpoint, 57 Features: make(map[string]bool, len(a.Features)), 58 } 59 60 for k, v := range a.Features { 61 c.Features[k] = v 62 } 63 64 return c 65 } 66 67 func (a *Configuration) disableAllFeatures() *Configuration { 68 for k := range a.Features { 69 a.Features[k] = false 70 } 71 return a 72 }