Documentation ¶
Index ¶
- Constants
- Variables
- func CanonicalUserAgentProduct(product string) string
- type DB
- type NewOffer
- type Offer
- type OfferStatus
- type OfferType
- type Offers
- type PartnerInfo
- type PartnerList
- type PartnersDB
- type PartnersService
- func (service *PartnersService) All(ctx context.Context) ([]PartnerInfo, error)
- func (service *PartnersService) ByName(ctx context.Context, name string) (PartnerInfo, error)
- func (service *PartnersService) ByUserAgent(ctx context.Context, userAgentString string) (PartnerInfo, error)
- func (service *PartnersService) GeneratePartnerLink(ctx context.Context, offerName string) ([]string, error)
- func (service *PartnersService) GetActiveOffer(ctx context.Context, offers Offers, offerType OfferType, partnerID string) (offer *Offer, err error)
- type PartnersStaticDB
- func (db *PartnersStaticDB) All(ctx context.Context) ([]PartnerInfo, error)
- func (db *PartnersStaticDB) ByID(ctx context.Context, id string) (PartnerInfo, error)
- func (db *PartnersStaticDB) ByName(ctx context.Context, name string) (PartnerInfo, error)
- func (db *PartnersStaticDB) ByUserAgent(ctx context.Context, agent string) (PartnerInfo, error)
- type RedeemOffer
- type UpdateOffer
Constants ¶
const ( // Invalid is a default value for offers that don't have correct type associated with it. Invalid = OfferType(0) // FreeCredit is a type of offers used for Free Credit Program. FreeCredit = OfferType(1) // Referral is a type of offers used for Referral Program. Referral = OfferType(2) // Partner is an OfferType used be the Open Source Partner Program. Partner = OfferType(3) )
const ( // Done is the status of an offer that is no longer in use. Done = OfferStatus(iota) // Default is the status of an offer when there is no active offer. Default // Active is the status of an offer that is currently in use. Active )
Variables ¶
var ( // ErrPartners is the default error class for partners package. ErrPartners = errs.Class("partners") // ErrPartnerNotExist is returned when a particular partner does not exist. ErrPartnerNotExist = errs.Class("partner does not exist") )
var ( // ErrReachedMaxCapacity is the error class used when an offer has reached its redemption capacity. ErrReachedMaxCapacity = errs.Class("offer redemption has reached its capacity") // ErrOfferNotExist is the error class used when no current offer is set. ErrOfferNotExist = errs.Class("no current offer") )
var DefaultPartnersDB = func() PartnersDB { list := DefaultPartners() db, err := NewPartnersStaticDB(&list) if err != nil { panic(err) } return db }()
DefaultPartnersDB is current default settings.
Functions ¶
func CanonicalUserAgentProduct ¶ added in v0.26.0
CanonicalUserAgentProduct returns canonicalizes the user agent product, which is suitable for lookups.
Types ¶
type DB ¶
type DB interface { ListAll(ctx context.Context) (Offers, error) GetActiveOffersByType(ctx context.Context, offerType OfferType) (Offers, error) Create(ctx context.Context, offer *NewOffer) (*Offer, error) Finish(ctx context.Context, offerID int) error }
DB holds information about offer
architecture: Database
type NewOffer ¶
type NewOffer struct { Name string Description string AwardCredit currency.USD InviteeCredit currency.USD RedeemableCap int AwardCreditDurationDays int InviteeCreditDurationDays int ExpiresAt time.Time Status OfferStatus Type OfferType }
NewOffer holds information that's needed for creating a new offer.
type Offer ¶
type Offer struct { ID int Name string Description string AwardCredit currency.USD InviteeCredit currency.USD AwardCreditDurationDays int InviteeCreditDurationDays int RedeemableCap int ExpiresAt time.Time CreatedAt time.Time Status OfferStatus Type OfferType }
Offer contains info needed for giving users free credits through different offer programs.
type OfferStatus ¶
type OfferStatus int
OfferStatus represents the different stage an offer can have in its life-cycle.
func (OfferStatus) IsDefault ¶ added in v0.18.0
func (status OfferStatus) IsDefault() bool
IsDefault checks if a offer's status is default.
type PartnerInfo ¶ added in v0.16.0
PartnerInfo contains information about a partner.
func (*PartnerInfo) UserAgent ¶ added in v0.26.0
func (p *PartnerInfo) UserAgent() string
UserAgent returns canonical user agent.
type PartnerList ¶ added in v0.26.0
type PartnerList struct {
Partners []PartnerInfo
}
PartnerList defines a json struct for defining partners.
func DefaultPartners ¶ added in v0.26.0
func DefaultPartners() PartnerList
DefaultPartners lists Storj default open-source partners.
func PartnersListFromJSONFile ¶ added in v0.26.0
func PartnersListFromJSONFile(path string) (*PartnerList, error)
PartnersListFromJSONFile loads a json definition of partners.
type PartnersDB ¶ added in v0.26.0
type PartnersDB interface { // All returns all partners. All(ctx context.Context) ([]PartnerInfo, error) // ByName returns partner definitions for a given name. ByName(ctx context.Context, name string) (PartnerInfo, error) // ByID returns partner definition corresponding to an id. ByID(ctx context.Context, id string) (PartnerInfo, error) // ByUserAgent returns partner definition corresponding to an user agent string. ByUserAgent(ctx context.Context, agent string) (PartnerInfo, error) }
PartnersDB allows access to partners database.
architecture: Database
type PartnersService ¶ added in v0.26.0
type PartnersService struct {
// contains filtered or unexported fields
}
PartnersService allows manipulating and accessing partner information.
architecture: Service
func NewPartnersService ¶ added in v0.26.0
func NewPartnersService(log *zap.Logger, db PartnersDB, domains []string) *PartnersService
NewPartnersService returns a service for handling partner information.
func (*PartnersService) All ¶ added in v0.26.0
func (service *PartnersService) All(ctx context.Context) ([]PartnerInfo, error)
All returns all partners.
func (*PartnersService) ByName ¶ added in v0.27.0
func (service *PartnersService) ByName(ctx context.Context, name string) (PartnerInfo, error)
ByName looks up partner by name.
func (*PartnersService) ByUserAgent ¶ added in v0.27.0
func (service *PartnersService) ByUserAgent(ctx context.Context, userAgentString string) (PartnerInfo, error)
ByUserAgent looks up partner by user agent.
func (*PartnersService) GeneratePartnerLink ¶ added in v0.26.0
func (service *PartnersService) GeneratePartnerLink(ctx context.Context, offerName string) ([]string, error)
GeneratePartnerLink returns partner referral link.
func (*PartnersService) GetActiveOffer ¶ added in v0.26.0
func (service *PartnersService) GetActiveOffer(ctx context.Context, offers Offers, offerType OfferType, partnerID string) (offer *Offer, err error)
GetActiveOffer returns an offer that is active based on its type.
type PartnersStaticDB ¶ added in v0.26.0
type PartnersStaticDB struct {
// contains filtered or unexported fields
}
PartnersStaticDB implements partner lookup based on a static definition.
architecture: Database Implementation
func NewPartnersStaticDB ¶ added in v0.26.0
func NewPartnersStaticDB(list *PartnerList) (*PartnersStaticDB, error)
NewPartnersStaticDB creates a new PartnersStaticDB.
func (*PartnersStaticDB) All ¶ added in v0.26.0
func (db *PartnersStaticDB) All(ctx context.Context) ([]PartnerInfo, error)
All returns all partners.
func (*PartnersStaticDB) ByID ¶ added in v0.26.0
func (db *PartnersStaticDB) ByID(ctx context.Context, id string) (PartnerInfo, error)
ByID returns partner definition corresponding to an id.
func (*PartnersStaticDB) ByName ¶ added in v0.26.0
func (db *PartnersStaticDB) ByName(ctx context.Context, name string) (PartnerInfo, error)
ByName returns partner definitions for a given name. Name is case insensitive.
func (*PartnersStaticDB) ByUserAgent ¶ added in v0.26.0
func (db *PartnersStaticDB) ByUserAgent(ctx context.Context, agent string) (PartnerInfo, error)
ByUserAgent returns partner definition corresponding to an user agent product string.
type RedeemOffer ¶ added in v0.18.0
type RedeemOffer struct { RedeemableCap int Status OfferStatus Type OfferType }
RedeemOffer holds field needed for redeem an offer.
type UpdateOffer ¶
type UpdateOffer struct { ID int Status OfferStatus ExpiresAt time.Time }
UpdateOffer holds fields needed for update an offer.