Documentation ¶
Index ¶
- Constants
- func ClaimOffer(ctx context.Context, db runner.Connection, ...) (dat.JSON, bool, int64, error)
- func ClaimOfferPlayer(ctx context.Context, db runner.Connection, offerPlayer *OfferPlayer, ...) error
- func CreateOfferPlayer(ctx context.Context, db runner.Connection, offerPlayer *OfferPlayer, ...) error
- func GetAvailableOffers(ctx context.Context, db runner.Connection, offersCache *cache.Cache, ...) (map[string][]*OfferToReturn, error)
- func GetDB(host string, user string, port int, sslmode string, dbName string, ...) (runner.Connection, error)
- func GetEnabledOffersKey(gameID string) string
- func IsForeignKeyViolationError(err error) (*pq.Error, bool)
- func IsNoRowsInResultSetError(err error) bool
- func SetEnabledOffer(ctx context.Context, db runner.Connection, gameID, id string, enabled bool, ...) error
- func ShouldPing(db *sql.DB, timeout time.Duration) error
- func UpsertGame(ctx context.Context, db runner.Connection, game *Game, t time.Time, ...) error
- func ValidateString(s string) bool
- func ViewOffer(ctx context.Context, db runner.Connection, ...) (bool, int64, error)
- func ViewOfferPlayer(ctx context.Context, db runner.Connection, offerPlayer *OfferPlayer, ...) error
- type ClaimOfferPayload
- type Clock
- type DefaultTrigger
- type FrequencyOrPeriod
- type Game
- type MetricsReporter
- type MixedMetricsReporter
- func (m *MixedMetricsReporter) AddReporter(mr MetricsReporter)
- func (m *MixedMetricsReporter) WithDatastoreSegment(table, operation string, f func() error) error
- func (m *MixedMetricsReporter) WithExternalSegment(url string, f func() error) error
- func (m *MixedMetricsReporter) WithSegment(name string, f func() error) error
- type Offer
- func GetEnabledOffers(ctx context.Context, db runner.Connection, gameID string, ...) ([]*Offer, error)
- func GetOfferByID(ctx context.Context, db runner.Connection, gameID, id string, ...) (*Offer, error)
- func InsertOffer(ctx context.Context, db runner.Connection, offer *Offer, ...) (*Offer, error)
- func ListOffers(ctx context.Context, db runner.Connection, gameID string, limit, offset uint64, ...) ([]*Offer, int, error)
- func UpdateOffer(ctx context.Context, db runner.Connection, offer *Offer, ...) (*Offer, error)
- type OfferImpressionPayload
- type OfferInstance
- type OfferInstanceOffer
- type OfferPlayer
- type OfferToReturn
- type OfferVersion
- type RealClock
- type TimeTrigger
- type Times
- type Trigger
Constants ¶
const SegmentInsect = "Database/Insect"
SegmentInsect represents a segment
const SegmentInsert = "Database/Insert"
SegmentInsert represents a segment
const SegmentModel = "Model"
SegmentModel represents a segment
const SegmentPostgres = "PostgreSQL"
SegmentPostgres represents a segment
const SegmentSelect = "Database/Select"
SegmentSelect represents a segment
const SegmentSerialization = "Serialization"
SegmentSerialization represents a segment
const SegmentUpdate = "Database/Update"
SegmentUpdate represents a segment
const SegmentUpsert = "Database/Upsert"
SegmentUpsert represents a segment
Variables ¶
This section is empty.
Functions ¶
func ClaimOffer ¶
func ClaimOffer( ctx context.Context, db runner.Connection, gameID, offerInstanceID, playerID, productID, transactionID string, timestamp int64, t time.Time, mr *MixedMetricsReporter, ) (dat.JSON, bool, int64, error)
ClaimOffer claims the offer
func ClaimOfferPlayer ¶
func ClaimOfferPlayer(ctx context.Context, db runner.Connection, offerPlayer *OfferPlayer, t time.Time, mr *MixedMetricsReporter) error
ClaimOfferPlayer increments the claim counter and updates the timestamp
func CreateOfferPlayer ¶
func CreateOfferPlayer(ctx context.Context, db runner.Connection, offerPlayer *OfferPlayer, mr *MixedMetricsReporter) error
CreateOfferPlayer creates an offer player
func GetAvailableOffers ¶
func GetAvailableOffers( ctx context.Context, db runner.Connection, offersCache *cache.Cache, gameID, playerID string, t time.Time, expireDuration time.Duration, filterAttrs map[string]string, allowInefficientQueries bool, mr *MixedMetricsReporter, ) (map[string][]*OfferToReturn, error)
GetAvailableOffers returns the offers that match the criteria of enabled offer templates
func GetDB ¶
func GetDB( host string, user string, port int, sslmode string, dbName string, password string, maxIdleConns, maxOpenConns int, connectionTimeoutMS int, ) (runner.Connection, error)
GetDB Connection using the given properties
func GetEnabledOffersKey ¶
GetEnabledOffersKey returns the key of the current enabled offers
func IsForeignKeyViolationError ¶
IsForeignKeyViolationError returns true if the error is a pq error stating a foreign key has been violated
func IsNoRowsInResultSetError ¶
IsNoRowsInResultSetError returns true if the error is a sqlx error stating that now rows were found
func SetEnabledOffer ¶
func SetEnabledOffer(ctx context.Context, db runner.Connection, gameID, id string, enabled bool, offersCache *cache.Cache, mr *MixedMetricsReporter) error
SetEnabledOffer can enable or disable an offer template
func UpsertGame ¶
func UpsertGame(ctx context.Context, db runner.Connection, game *Game, t time.Time, mr *MixedMetricsReporter) error
UpsertGame updates a game with new meta or insert with the new UUID
func ValidateString ¶
ValidateString validates the string contains only valid characters for filters
func ViewOffer ¶
func ViewOffer( ctx context.Context, db runner.Connection, gameID, offerInstanceID, playerID, impressionID string, t time.Time, mr *MixedMetricsReporter, ) (bool, int64, error)
ViewOffer views the offer
func ViewOfferPlayer ¶
func ViewOfferPlayer(ctx context.Context, db runner.Connection, offerPlayer *OfferPlayer, t time.Time, mr *MixedMetricsReporter) error
ViewOfferPlayer increments the view counter and updates the timestamp
Types ¶
type ClaimOfferPayload ¶
type ClaimOfferPayload struct { GameID string `json:"gameId" valid:"matches(^[^-][a-zA-Z0-9-_]*$),stringlength(1|255),required"` PlayerID string `json:"playerId" valid:"ascii,stringlength(1|1000),required"` ProductID string `json:"productId" valid:"ascii,stringlength(1|255)"` Timestamp int64 `json:"timestamp" valid:"int64,required"` TransactionID string `json:"transactionId" valid:"ascii,stringlength(1|1000),required"` OfferInstanceID string `json:"id" valid:"uuidv4,optional"` }
ClaimOfferPayload has required fields for claiming an offer
type DefaultTrigger ¶
type DefaultTrigger struct{}
DefaultTrigger implements interface Trigger
func (DefaultTrigger) IsTriggered ¶
func (dt DefaultTrigger) IsTriggered(times interface{}, user interface{}) bool
IsTriggered returns the current time
type FrequencyOrPeriod ¶
FrequencyOrPeriod is the struct for basic Frequency and Period types
type Game ¶
type Game struct { ID string `db:"id" json:"id" valid:"matches(^[^-][a-zA-Z0-9-_]*$),stringlength(1|255)"` Name string `db:"name" json:"name" valid:"ascii,stringlength(1|255),required"` Metadata dat.JSON `db:"metadata" json:"metadata" valid:"JSONObject"` //TODO: Validate dates CreatedAt dat.NullTime `db:"created_at" json:"createdAt" valid:""` UpdatedAt dat.NullTime `db:"updated_at" json:"updatedAt" valid:""` }
Game represents a tenant in offers API
func GetGameByID ¶
func GetGameByID(ctx context.Context, db runner.Connection, id string, mr *MixedMetricsReporter) (*Game, error)
GetGameByID returns a game by it's pk
func ListGames ¶
func ListGames(ctx context.Context, db runner.Connection, mr *MixedMetricsReporter) ([]*Game, error)
ListGames returns a the full list of games
func (*Game) GetMetadata ¶
GetMetadata for game
type MetricsReporter ¶
type MetricsReporter interface { StartSegment(string) map[string]interface{} EndSegment(map[string]interface{}, string) StartDatastoreSegment(datastore, collection, operation string) map[string]interface{} EndDatastoreSegment(map[string]interface{}) StartExternalSegment(string) map[string]interface{} EndExternalSegment(map[string]interface{}) }
MetricsReporter is a contract for reporters of metrics
type MixedMetricsReporter ¶
type MixedMetricsReporter struct { MetricsReporters []MetricsReporter Func func(name string, f func() error) error }
MixedMetricsReporter calls other metrics reporters
func NewMixedMetricsReporter ¶
func NewMixedMetricsReporter() *MixedMetricsReporter
NewMixedMetricsReporter ctor
func (*MixedMetricsReporter) AddReporter ¶
func (m *MixedMetricsReporter) AddReporter(mr MetricsReporter)
AddReporter to metrics reporter
func (*MixedMetricsReporter) WithDatastoreSegment ¶
func (m *MixedMetricsReporter) WithDatastoreSegment(table, operation string, f func() error) error
WithDatastoreSegment that calls all the other metrics reporters
func (*MixedMetricsReporter) WithExternalSegment ¶
func (m *MixedMetricsReporter) WithExternalSegment(url string, f func() error) error
WithExternalSegment that calls all the other metrics reporters
func (*MixedMetricsReporter) WithSegment ¶
func (m *MixedMetricsReporter) WithSegment(name string, f func() error) error
WithSegment that calls all the other metrics reporters
type Offer ¶
type Offer struct { ID string `db:"id" json:"id" valid:"uuidv4"` GameID string `db:"game_id" json:"gameId" valid:"matches(^[^-][a-zA-Z0-9-_]*$),stringlength(1|255),required"` Name string `db:"name" json:"name" valid:"ascii,stringlength(1|255),required"` Period dat.JSON `db:"period" json:"period" valid:"RequiredJSONObject"` Frequency dat.JSON `db:"frequency" json:"frequency" valid:"RequiredJSONObject"` Trigger dat.JSON `db:"trigger" json:"trigger" valid:"RequiredJSONObject"` Placement string `db:"placement" json:"placement" valid:"ascii,stringlength(1|255),required"` Metadata dat.JSON `db:"metadata" json:"metadata" valid:"JSONObject"` ProductID string `db:"product_id" json:"productId,omitempty" valid:"ascii,stringlength(1|255)"` Contents dat.JSON `db:"contents" json:"contents" valid:"RequiredJSONObject"` Enabled bool `db:"enabled" json:"enabled" valid:"matches(^(true|false)$),optional"` Version int `db:"version" json:"version" valid:"int,optional"` CreatedAt time.Time `db:"created_at" json:"createdAt" valid:"optional"` Filters dat.JSON `db:"filters" json:"filters" valid:"FilterJSONObject"` Cost dat.JSON `db:"cost" json:"cost,omitempty" valid:"JSONObject"` }
Offer contains the parameters of an offer
func GetEnabledOffers ¶
func GetEnabledOffers(ctx context.Context, db runner.Connection, gameID string, offersCache *cache.Cache, expireDuration time.Duration, currentTime time.Time, filterAttrs map[string]string, allowInefficientQueries bool, mr *MixedMetricsReporter) ([]*Offer, error)
GetEnabledOffers returns all the enabled offers and matching offers
func GetOfferByID ¶
func GetOfferByID(ctx context.Context, db runner.Connection, gameID, id string, mr *MixedMetricsReporter) (*Offer, error)
GetOfferByID returns Offer by ID
func InsertOffer ¶
func InsertOffer(ctx context.Context, db runner.Connection, offer *Offer, offersCache *cache.Cache, mr *MixedMetricsReporter) (*Offer, error)
InsertOffer inserts a new offer template into DB
func ListOffers ¶
func ListOffers( ctx context.Context, db runner.Connection, gameID string, limit, offset uint64, mr *MixedMetricsReporter, ) ([]*Offer, int, error)
ListOffers returns all the offer templates for a given game return the number of pages using the number of offers and given the limit for each page
func UpdateOffer ¶
func UpdateOffer(ctx context.Context, db runner.Connection, offer *Offer, offersCache *cache.Cache, mr *MixedMetricsReporter) (*Offer, error)
UpdateOffer updates a given offer
type OfferImpressionPayload ¶
type OfferImpressionPayload struct { GameID string `json:"gameId" valid:"matches(^[^-][a-zA-Z0-9-_]*$),stringlength(1|255),required"` PlayerID string `json:"playerId" valid:"ascii,stringlength(1|1000),required"` ImpressionID string `json:"impressionId" valid:"uuidv4,required"` }
OfferImpressionPayload has required fields for an offer impression
type OfferInstance ¶
type OfferInstance struct { ID string `db:"id" json:"id" valid:"uuidv4,required"` GameID string `db:"game_id" json:"gameId" valid:"matches(^[^-][a-zA-Z0-9-_]*$),stringlength(1|255),required"` PlayerID string `db:"player_id" json:"playerId" valid:"ascii,stringlength(1|1000),required"` OfferID string `db:"offer_id" json:"offerId" valid:"uuidv4,required"` OfferVersion int `db:"offer_version" json:"offerVersion" valid:"int,required"` Contents dat.JSON `db:"contents" json:"contents" valid:"RequiredJSONObject"` ProductID string `db:"product_id" json:"productId" valid:"ascii,stringlength(1|255)"` Cost dat.JSON `db:"cost" json:"cost" valid:"JSONObject"` CreatedAt dat.NullTime `db:"created_at" json:"createdAt" valid:""` }
OfferInstance represents a tenant in offers API it cannot be updated, only inserted
type OfferInstanceOffer ¶
type OfferInstanceOffer struct { ID string `db:"id" json:"id" valid:"uuidv4,required"` GameID string `db:"game_id" json:"gameId" valid:"matches(^[^-][a-zA-Z0-9-_]*$),stringlength(1|255),required"` OfferID string `db:"offer_id" json:"offerId" valid:"uuidv4,required"` Contents dat.JSON `db:"contents" json:"contents" valid:"RequiredJSONObject"` Enabled bool `db:"enabled" json:"enabled"` }
OfferInstanceOffer is a join of OfferInstance with offer
type OfferPlayer ¶
type OfferPlayer struct { ID string `db:"id" json:"id" valid:"uuidv4,required"` GameID string `db:"game_id" json:"gameId" valid:"matches(^[^-][a-zA-Z0-9-_]*$),stringlength(1|255),required"` PlayerID string `db:"player_id" json:"playerId" valid:"ascii,stringlength(1|1000),required"` OfferID string `db:"offer_id" json:"offerId" valid:"uuidv4,required"` ClaimCounter int `db:"claim_counter" json:"claimCounter" valid:"int"` ClaimTimestamp dat.NullTime `db:"claim_timestamp" json:"claimTimestamp" valid:""` ViewCounter int `db:"view_counter" json:"viewCounter" valid:"int"` ViewTimestamp dat.NullTime `db:"view_timestamp" json:"viewTimestamp" valid:""` Transactions dat.JSON `db:"transactions" json:"transactions" valid:""` Impressions dat.JSON `db:"impressions" json:"impressions" valid:""` }
OfferPlayer represents an offer seen by a player
func GetOfferPlayer ¶
func GetOfferPlayer(ctx context.Context, db runner.Connection, gameID, playerID, offerID string, mr *MixedMetricsReporter) (*OfferPlayer, error)
GetOfferPlayer returns an offer player
func GetOffersByPlayer ¶
func GetOffersByPlayer(ctx context.Context, db runner.Connection, gameID, playerID string, mr *MixedMetricsReporter) ([]*OfferPlayer, error)
GetOffersByPlayer returns all offers by player
type OfferToReturn ¶
type OfferToReturn struct { ID string `db:"id" json:"id"` ProductID string `db:"product_id" json:"productId,omitempty"` Cost dat.JSON `db:"cost" json:"cost,omitempty" valid:"JSONObject"` Contents dat.JSON `db:"contents" json:"contents"` Metadata dat.JSON `db:"metadata" json:"metadata"` ExpireAt int64 `db:"expire_at" json:"expireAt"` }
OfferToReturn has the fields for the returned offer
func GetOfferInfo ¶
func GetOfferInfo( ctx context.Context, db runner.Connection, gameID, offerInstanceID string, expireDuration time.Duration, mr *MixedMetricsReporter, ) (*OfferToReturn, error)
GetOfferInfo returns the offers that match the criteria of enabled offer templates
type OfferVersion ¶
type OfferVersion struct { ID string `db:"id" json:"id" valid:"uuidv4,required"` GameID string `db:"game_id" json:"gameId" valid:"matches(^[^-][a-zA-Z0-9-_]*$),stringlength(1|255),required"` OfferID string `db:"offer_id" json:"offerId" valid:"uuidv4,required"` OfferVersion int `db:"offer_version" json:"offerVersion" valid:"int,required"` Contents dat.JSON `db:"contents" json:"contents" valid:"RequiredJSONObject"` ProductID string `db:"product_id" json:"productId" valid:"ascii,stringlength(1|255)"` Cost dat.JSON `db:"cost" json:"cost" valid:"JSONObject"` CreatedAt dat.NullTime `db:"created_at" json:"createdAt" valid:""` }
OfferVersion represents a tenant in offers API it cannot be updated, only inserted
type TimeTrigger ¶
type TimeTrigger struct{}
TimeTrigger implements interface Trigger
func (TimeTrigger) IsTriggered ¶
func (tt TimeTrigger) IsTriggered(times interface{}, now interface{}) bool
IsTriggered returns the current time