-
Notifications
You must be signed in to change notification settings - Fork 394
/
partner.go
47 lines (37 loc) · 1.1 KB
/
partner.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
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package rewards
import (
"encoding/json"
"os"
"strings"
"github.com/zeebo/errs"
"storj.io/common/uuid"
)
// PartnerList defines a json struct for defining partners.
type PartnerList struct {
Partners []PartnerInfo
}
// PartnerInfo contains information about a partner.
type PartnerInfo struct {
Name string
ID string
UUID uuid.UUID
}
// UserAgent returns canonical user agent.
func (p *PartnerInfo) UserAgent() string { return p.Name }
// CanonicalUserAgentProduct returns canonicalizes the user agent product, which is suitable for lookups.
func CanonicalUserAgentProduct(product string) string { return strings.ToLower(product) }
// PartnersListFromJSONFile loads a json definition of partners.
func PartnersListFromJSONFile(path string) (*PartnerList, error) {
file, err := os.Open(path)
if err != nil {
return nil, ErrPartners.Wrap(err)
}
defer func() {
err = errs.Combine(err, ErrPartners.Wrap(file.Close()))
}()
var list PartnerList
err = json.NewDecoder(file).Decode(&list)
return &list, ErrPartners.Wrap(err)
}