Documentation ¶
Index ¶
- func MakeHandler(svc Service, opts ...kithttp.ServerOption) http.Handler
- type Bucket
- type Comparator
- type Context
- type ContextLocale
- type ContextUser
- type Criteria
- type Criterion
- type CriterionKey
- type Decisions
- type Kind
- type List
- type PGRepo
- func (r *PGRepo) Create(input Rule) (Rule, error)
- func (r *PGRepo) GetByID(id string) (Rule, error)
- func (r *PGRepo) ListActive(configID string, now time.Time) ([]Rule, error)
- func (r *PGRepo) ListAll() ([]Rule, error)
- func (r *PGRepo) Setup() error
- func (r *PGRepo) Teardown() error
- func (r *PGRepo) UpdateWith(input Rule) (Rule, error)
- type PGRepoOption
- type Parameters
- type Repo
- type RepoMiddleware
- type ResponseParameter
- type ResponseParameters
- type Rule
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MakeHandler ¶
func MakeHandler(svc Service, opts ...kithttp.ServerOption) http.Handler
MakeHandler sets up an http.Handler with all public API endpoints mounted.
Types ¶
type Bucket ¶
type Bucket struct { Name string Parameters Parameters Percentage int }
Bucket is a distinct set of parameters that can be used to control segregation by percentage split. Rules which are not of kind experiment will only have one bucket.
type Comparator ¶
type Comparator int8
Comparator defines the type of comparison for a Criterion.
const ( ComparatorGT Comparator = iota ComparatorEQ ComparatorNQ ComparatorIN )
Comparators.
func (Comparator) String ¶
func (c Comparator) String() string
type Context ¶
type Context struct { User ContextUser Locale ContextLocale }
Context carries information for rule decisions to match criteria.
type ContextLocale ¶
ContextLocale bundles locale information for rule criteria to match.
type ContextUser ¶
ContextUser bundles user information for rule criteria to match.
type Criterion ¶
type Criterion struct { Comparator Comparator Key CriterionKey Value interface{} Path string }
Criterion is a single decision which can be evaluated to decide if a Rule should be applied.
func (Criterion) MarshalJSON ¶
MarshalJSON to satisfy json.Marshaler.
func (*Criterion) UnmarshalJSON ¶
UnmarshalJSON to satisfy json.Unmarshaler.
type CriterionKey ¶
type CriterionKey int
CriterionKey is the set of possible input to match on.
const ( DeviceLocationLocale CriterionKey = iota + 101 DeviceLocationOffset DeviceOSPlatform DeviceOSVersion )
Device context keys.
const ( MetadataBool CriterionKey = iota + 201 MetadataNumber MetadataString )
Metadata context keys.
const ( UserAge CriterionKey = iota + 301 UserRegistered UserID UserSubscription )
User context keys.
const (
AppVersion CriterionKey = iota + 1
)
App context keys.
const (
ValidDate CriterionKey = iota + 401
)
Date comparison key
func (CriterionKey) String ¶
func (k CriterionKey) String() string
type Decisions ¶
Decisions reflects a matrix of rules applied to a config and if present the results of dice rolls for percenatage based decisions.
type PGRepo ¶
type PGRepo struct {
// contains filtered or unexported fields
}
PGRepo is a Postgres backed Repo implementation.
func (*PGRepo) ListActive ¶
ListActive returns all active rules.
type PGRepoOption ¶
type PGRepoOption func(*PGRepo)
PGRepoOption sets an optional parameter on the repo.
func PGRepoSchema ¶
func PGRepoSchema(schema string) PGRepoOption
PGRepoSchema sets the namespacing of the Postgres tables to a non-default schema.
type Parameters ¶
type Parameters map[string]interface{}
Parameters is the set of keys and their new values that an applied rule sets.
type Repo ¶
type Repo interface { Create(input Rule) (Rule, error) GetByID(string) (Rule, error) UpdateWith(input Rule) (Rule, error) ListAll() ([]Rule, error) ListActive(configID string, now time.Time) ([]Rule, error) // contains filtered or unexported methods }
Repo provides access to rules.
func NewPostgresRepo ¶
func NewPostgresRepo(db *sqlx.DB, options ...PGRepoOption) Repo
NewPostgresRepo returns a Postgres backed Repo implementation.
type RepoMiddleware ¶
RepoMiddleware is a chainable behaviour modifier for Repo.
func NewRuleRepoInstrumentMiddleware ¶
func NewRuleRepoInstrumentMiddleware( opObserve instrument.ObserveRepoFunc, store string, ) RepoMiddleware
NewRuleRepoInstrumentMiddleware wraps the next Repo and adds Prometheus instrumentation capabilities.
func NewRuleRepoLogMiddleware ¶
func NewRuleRepoLogMiddleware(logger log.Logger, store string) RepoMiddleware
NewRuleRepoLogMiddleware wraps the next Repo with logging capabilities.
type ResponseParameter ¶
type ResponseParameter struct { Name string `json:"name"` Value interface{} `json:"value"` }
ResponseParameter used to represent a parameter on the wire.
func (ResponseParameter) MarshalJSON ¶
func (r ResponseParameter) MarshalJSON() ([]byte, error)
MarshalJSON to satisfy json.Marshaler and include the value type of the parameter for clients to make easy decisions when materialising it.
type ResponseParameters ¶
type ResponseParameters []ResponseParameter
ResponseParameters is a collection of ResponseParameter.
func (ResponseParameters) Len ¶
func (r ResponseParameters) Len() int
func (ResponseParameters) Less ¶
func (r ResponseParameters) Less(i, j int) bool
func (ResponseParameters) Swap ¶
func (r ResponseParameters) Swap(i, j int)
type Rule ¶
type Rule struct { ID string // contains filtered or unexported fields }
Rule facilitates the overide of base configs with consumer provided parameters.
func New ¶
func New( id, configID, name, description string, kind Kind, active bool, criteria Criteria, buckets []Bucket, rollout *uint8, ) (Rule, error)
New returns a valid rule.
func (Rule) Run ¶
func (r Rule) Run(input Parameters, ctx Context, decisions []int, randInt generate.RandPercentageFunc) (Parameters, []int, error)
Run given an input params and context will try to match based on the rules Criteria and if matched overrides the input params with its own.