storj/satellite/rewards/partner.go
Egon Elbre 1024bf9ce1 all: simplify uuid usage
Instead of uuid.Parse, use uuid.FromString.
This removes a bunch of pointer management logic.

Change-Id: Id25bd174eb43c71d00b450158a198abafd8958f2
2020-04-02 13:45:19 +00:00

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)
}