1024bf9ce1
Instead of uuid.Parse, use uuid.FromString. This removes a bunch of pointer management logic. Change-Id: Id25bd174eb43c71d00b450158a198abafd8958f2
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
// 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)
|
|
}
|