api

package
v4.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2024 License: Apache-2.0 Imports: 5 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DISABLED_VARIANT = &Variant{
	Name:           "disabled",
	Enabled:        false,
	FeatureEnabled: false,
}

Functions

This section is empty.

Types

type Constraint

type Constraint struct {
	// ContextName is the context name of the constraint.
	ContextName string `json:"contextName"`

	// Operator is the operator of the constraint.
	Operator Operator `json:"operator"`

	// Values is the list of target values for multi-valued constraints.
	Values []string `json:"values"`

	// Value is the target value single-value constraints.
	Value string `json:"value"`

	// CaseInsensitive makes the string operators case-insensitive.
	CaseInsensitive bool `json:"caseInsensitive"`

	// Inverted flips the constraint check result.
	Inverted bool `json:"inverted"`
}

Constraint represents a constraint on a particular context value.

type Dependency

type Dependency struct {
	// Feature is the name of the feature toggle we depend upon
	Feature string `json:"feature"`
	// Variants contains a string of variants that the dependency should resolve to
	Variants *[]string `json:"variants"`
	// Enabled is the property that determines whether the dependency should be on or off
	// If the property is absent from the payload it's assumed to be default on
	Enabled *bool `json:"enabled"`
}

type Feature

type Feature struct {
	// Name is the name of the feature toggle.
	Name string `json:"name"`

	// Type is the type of the feature toggle.
	Type string `json:"type"`

	// Description is a description of the feature toggle.
	Description string `json:"description"`

	// Enabled indicates whether the feature was enabled or not.
	Enabled bool `json:"enabled"`

	// Strategies is a list of names of the strategies supported by the client.
	Strategies []Strategy `json:"strategies"`

	// CreatedAt is the creation time of the feature toggle.
	CreatedAt time.Time `json:"createdAt"`

	// Strategy is the strategy of the feature toggle.
	Strategy string `json:"strategy"`

	// Parameters is the parameters of the feature toggle.
	Parameters ParameterMap `json:"parameters"`

	// Variants is a list of variants of the feature toggle.
	Variants []VariantInternal `json:"variants"`

	// Dependencies is a list of feature toggle dependency objects
	Dependencies *[]Dependency `json:"dependencies"`

	// ImpressionData indicates whether the client SDK should emit an impression event
	ImpressionData bool `json:"impressionData"`
}

type FeatureResponse

type FeatureResponse struct {
	Response
	Features []Feature `json:"features"`
	Segments []Segment `json:"segments"`
}

func (FeatureResponse) FeatureMap

func (fr FeatureResponse) FeatureMap() map[string]interface{}

func (FeatureResponse) SegmentsMap

func (fr FeatureResponse) SegmentsMap() map[int][]Constraint

type Operator

type Operator string

Operator is a type representing a constraint operator

const (
	// OperatorIn indicates that the context values must be
	// contained within those specified in the constraint.
	OperatorIn Operator = "IN"

	// OperatorNotIn indicates that the context values must
	// NOT be contained within those specified in the constraint.
	OperatorNotIn Operator = "NOT_IN"

	// OperatorStrContains indicates that the context value
	// must contain the specified substring.
	OperatorStrContains Operator = "STR_CONTAINS"

	// OperatorStrStartsWith indicates that the context value
	// must have the specified prefix.
	OperatorStrStartsWith Operator = "STR_STARTS_WITH"

	// OperatorStrEndsWith indicates that the context value
	// must have the specified suffix.
	OperatorStrEndsWith Operator = "STR_ENDS_WITH"

	// OperatorNumEq indicates that the context value
	// must be equal to the specified number.
	OperatorNumEq Operator = "NUM_EQ"

	// OperatorNumLt indicates that the context value
	// must be less than the specified number.
	OperatorNumLt Operator = "NUM_LT"

	// OperatorNumLte indicates that the context value
	// must be less than or equal to the specified number.
	OperatorNumLte Operator = "NUM_LTE"

	// OperatorNumGt indicates that the context value
	// must be greater than the specified number.
	OperatorNumGt Operator = "NUM_GT"

	// OperatorNumGte indicates that the context value
	// must be greater than or equal to the specified number.
	OperatorNumGte Operator = "NUM_GTE"

	// OperatorDateBefore indicates that the context value
	// must be before the specified date.
	OperatorDateBefore Operator = "DATE_BEFORE"

	// OperatorDateAfter indicates that the context value
	// must be after the specified date.
	OperatorDateAfter Operator = "DATE_AFTER"

	// OperatorSemverEq indicates that the context value
	// must be equal to the specified SemVer version.
	OperatorSemverEq Operator = "SEMVER_EQ"

	// OperatorSemverLt indicates that the context value
	// must be less than the specified SemVer version.
	OperatorSemverLt Operator = "SEMVER_LT"

	// OperatorSemverGt indicates that the context value
	// must be greater than the specified SemVer version.
	OperatorSemverGt Operator = "SEMVER_GT"
)

type Override

type Override struct {
	// ContextName is the value of attribute context name
	ContextName string `json:"contextName"`
	// Values is the value of attribute values
	Values []string `json:"values"`
}

type ParameterDescription

type ParameterDescription struct {
	Name        string `json:"name"`
	Type        string `json:"type"`
	Description string `json:"description"`
	Required    bool   `json:"required"`
}

type ParameterMap

type ParameterMap map[string]interface{}

type Payload

type Payload struct {
	// Type is the type of the payload
	Type string `json:"type"`
	// Value is the value of the payload type
	Value string `json:"value"`
}

type Response

type Response struct {
	Version int `json:"version"`
}

type Segment

type Segment struct {
	Id          int          `json:"id"`
	Constraints []Constraint `json:"constraints"`
}

type Strategy

type Strategy struct {
	// Id is the name of the strategy.
	Id int `json:"id"`

	// Name is the name of the strategy.
	Name string `json:"name"`

	// Constraints is the constraints of the strategy.
	Constraints []Constraint `json:"constraints"`

	// Parameters is the parameters of the strategy.
	Parameters ParameterMap `json:"parameters"`

	Segments []int `json:"segments"`

	// Variants for a strategy
	Variants []VariantInternal `json:"variants"`
}

type StrategyDescription

type StrategyDescription struct {
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	Parameters  []ParameterDescription `json:"parameters"`
}

type StrategyResponse

type StrategyResponse struct {
	Response
	Strategies []StrategyDescription `json:"strategies"`
}

type StrategyResult

type StrategyResult struct {
	Enabled bool
	Variant *Variant
}

type Variant

type Variant struct {
	// Name is the value of the variant name.
	Name string `json:"name"`
	// Payload is the value of the variant payload
	Payload Payload `json:"payload"`
	// Enabled indicates whether the variant is enabled. This is only false when
	// it's a default variant.
	Enabled bool `json:"enabled"`
	// FeatureEnabled indicates whether the Feature for this variant is enabled.
	FeatureEnabled bool `json:"featureEnabled"`
}

func GetDefaultVariant

func GetDefaultVariant() *Variant

Get default variant if feature is not found or if the feature is disabled.

Rather than checking against this particular variant you should be checking the returned variant's Enabled and FeatureEnabled properties.

type VariantCollection

type VariantCollection struct {
	// groupId to evaluate the variant
	GroupId string
	// variants for a feature toggle or feature strategy
	Variants []VariantInternal
}

func (VariantCollection) GetVariant

func (vc VariantCollection) GetVariant(ctx *context.Context) *Variant

Get variant for a given feature which is considered as enabled

type VariantInternal

type VariantInternal struct {
	Variant
	// Weight is the traffic ratio for the request
	Weight int `json:"weight"`
	// WeightType can be fixed or variable
	WeightType string `json:"weightType"`
	Stickiness string `json:"stickiness"`
	// Override is used to get a variant accoording to the Unleash context field
	Overrides []Override `json:"overrides"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL