Documentation
¶
Index ¶
- Constants
- func HasReservedKey(attributes map[string]any) bool
- type Context
- type EvaluationContext
- func (u EvaluationContext) AddCustomAttribute(name string, value any)
- func (u EvaluationContext) ExtractGOFFProtectedFields() GoffContextSpecifics
- func (u EvaluationContext) GetCustom() map[string]any
- func (u EvaluationContext) GetKey() string
- func (u EvaluationContext) IsAnonymous() bool
- func (u EvaluationContext) MarshalJSON() ([]byte, error)
- func (u EvaluationContext) ToMap() map[string]any
- type EvaluationContextBuilder
- type GoffContextSpecifics
Constants ¶
const LegacyReservedKey = "gofeatureflag"
LegacyReservedKey is the name that GO Feature Flag clients send for ReservedKey. It is still accepted, ReservedKey wins when both are set.
const ReservedKey = "semaphore"
ReservedKey is the evaluation context attribute holding the Semaphore specific fields (currentDateTime, flagList, exporterMetadata).
Variables ¶
This section is empty.
Functions ¶
func HasReservedKey ¶
HasReservedKey tells if the attributes carry the reserved attribute, under any of its names.
Types ¶
type Context ¶
type Context interface {
// GetKey return the unique targetingKey for the context.
GetKey() string
// IsAnonymous return if the context is about an anonymous user or not.
IsAnonymous() bool
// GetCustom return all the attributes properties added to the context.
GetCustom() map[string]any
// AddCustomAttribute allows to add a attributes attribute into the context.
AddCustomAttribute(name string, value any)
// ExtractGOFFProtectedFields extract the goff specific attributes from the evaluation context.
ExtractGOFFProtectedFields() GoffContextSpecifics
}
type EvaluationContext ¶
type EvaluationContext struct {
// contains filtered or unexported fields
}
EvaluationContext contains specific attributes for your evaluation. Most of the time it is identifying a user browsing your site. The only mandatory property is the Key, which must a unique identifier. For authenticated users, this may be a username or e-mail address. For anonymous users, this could be an IP address or session ID.
EvaluationContext fields are immutable and can be accessed only via getter methods. To construct an EvaluationContext, use either a simple constructor (NewEvaluationContext) or the builder pattern with NewEvaluationContextBuilder.
func NewAnonymousEvaluationContext
deprecated
func NewAnonymousEvaluationContext(key string) EvaluationContext
Deprecated: NewAnonymousEvaluationContext is here for compatibility reason. Please use NewEvaluationContext instead and add a attributes attribute to know that it is an anonymous user.
ctx := NewEvaluationContext("my-targetingKey") ctx.AddCustomAttribute("anonymous", true).
func NewEvaluationContext ¶
func NewEvaluationContext(key string) EvaluationContext
NewEvaluationContext creates a new evaluation context identified by the given targetingKey.
func (EvaluationContext) AddCustomAttribute ¶
func (u EvaluationContext) AddCustomAttribute(name string, value any)
AddCustomAttribute allows to add a attributes attribute into the user.
func (EvaluationContext) ExtractGOFFProtectedFields ¶
func (u EvaluationContext) ExtractGOFFProtectedFields() GoffContextSpecifics
ExtractGOFFProtectedFields extract the Semaphore specific attributes from the evaluation context. They are read from the "semaphore" attribute and, for the clients of Semaphore, from the legacy "gofeatureflag" attribute. When both are set, a field of "semaphore" wins.
func (EvaluationContext) GetCustom ¶
func (u EvaluationContext) GetCustom() map[string]any
GetCustom return all the attributes properties of a user.
func (EvaluationContext) GetKey ¶
func (u EvaluationContext) GetKey() string
GetKey return the unique targetingKey for the user.
func (EvaluationContext) IsAnonymous ¶
func (u EvaluationContext) IsAnonymous() bool
IsAnonymous return if the user is anonymous or not.
func (EvaluationContext) MarshalJSON ¶
func (u EvaluationContext) MarshalJSON() ([]byte, error)
MarshalJSON is a custom JSON marshaller for EvaluationContext. It will only marshal the targetingKey and the attributes of the context and avoid to expose the internal structure.
func (EvaluationContext) ToMap ¶
func (u EvaluationContext) ToMap() map[string]any
ToMap returns a new map containing the context attributes plus the targetingKey. The returned map is a shallow copy: the top-level map is independent from the context, so adding or removing keys does not affect it, but nested reference values (maps, slices, pointers) are shared and mutating them will also mutate the context.
type EvaluationContextBuilder ¶
type EvaluationContextBuilder interface {
// Deprecated: Anonymous is to flag the context for an anonymous context or not.
// This function is here for compatibility reason, please consider to use AddCustom("anonymous", true)
// instead of using this function.
Anonymous(bool) EvaluationContextBuilder
AddCustom(key string, value any) EvaluationContextBuilder
Build() EvaluationContext
}
EvaluationContextBuilder is a builder to create an EvaluationContext.
func NewEvaluationContextBuilder ¶
func NewEvaluationContextBuilder(key string) EvaluationContextBuilder
NewEvaluationContextBuilder constructs a new EvaluationContextBuilder, specifying the user targetingKey.
For authenticated users, the targetingKey may be a username or e-mail address. For anonymous users, this could be an IP address or session ID.
type GoffContextSpecifics ¶
type GoffContextSpecifics struct {
// CurrentDateTime is the current date time to use for the evaluation.
CurrentDateTime *time.Time `json:"currentDateTime"`
// ExporterMetadata is the metadata to be used by the exporter.
ExporterMetadata map[string]any `json:"exporterMetadata"`
// FlagList is the list of flags to evaluate in a bulk evaluation.
FlagList []string `json:"flagList"`
// UsedLegacyKey is true when the context carried these fields under the legacy attribute name
// (LegacyReservedKey). The code that evaluates the flags reports it, once, through its own
// legacy.Warner: extracting the fields has no owner to warn.
UsedLegacyKey bool `json:"-"`
}