Documentation
¶
Overview ¶
Package flagstate builds the state of a flag evaluation returned by the all flags and flag evaluation APIs.
Index ¶
Constants ¶
const MetadataSegmentStatus = "semaphore_segmentStatus"
MetadataSegmentStatus is the response metadata key of the health of the segment lookups of an evaluation.
Variables ¶
This section is empty.
Functions ¶
func WithSegmentStatus ¶ added in v0.2.0
WithSegmentStatus adds the MetadataSegmentStatus key to the metadata of an evaluation whose segment lookups were not healthy (STALE, NOT_CONFIGURED or STORE_ERROR). A healthy evaluation, and one with no segment, get the metadata back untouched: no copy, no allocation. The map belongs to the evaluation, so the key is added to it.
Types ¶
type AllFlags ¶
type AllFlags struct {
// contains filtered or unexported fields
}
AllFlags is a snapshot of the state of multiple feature flags with regard to a specific user. This is the return type of the AllFlagsState method of the client. Serializing this object to JSON MarshalJSON() will produce a JSON you can sent to your front-end.
func NewAllFlags ¶
func NewAllFlags() AllFlags
NewAllFlags will create a new AllFlags for a specific user. It sets valid to true, because until we have an error everything is valid.
func (AllFlags) MarshalJSON ¶
MarshalJSON is serializing the object to JSON, it will produce a JSON you can sent to your front-end.
type FlagState ¶
type FlagState struct {
Value any `json:"value"`
Timestamp int64 `json:"timestamp"`
VariationType string `json:"variationType"`
TrackEvents bool `json:"trackEvents"`
Failed bool `json:"-"`
ErrorCode flagdef.ErrorCode `json:"errorCode"`
ErrorDetails string `json:"errorDetails,omitempty"`
Reason flagdef.ResolutionReason `json:"reason"`
Metadata map[string]any `json:"metadata,omitempty"`
// SegmentStatus is the health of the segment lookups; it is not part of the JSON, see [WithSegmentStatus].
SegmentStatus segment.Status `json:"-"`
}
FlagState represents the state of an individual feature flag, with regard to a specific user, when it was called.
func FromFlagEvaluation ¶
func FromFlagEvaluation(key string, evaluationCtx ffcontext.Context, flagCtx flagdef.Context, currentFlag flagdef.Flag) FlagState
FromFlagEvaluation builds the state of a flag evaluated now.
func FromFlagEvaluationAt ¶
func FromFlagEvaluationAt(evaluatedAt time.Time, key string, evaluationCtx ffcontext.Context, flagCtx flagdef.Context, currentFlag flagdef.Flag) FlagState
FromFlagEvaluationAt builds the state of a flag evaluated at the given instant.
func (*FlagState) MetadataWithStatus ¶ added in v0.2.0
MetadataWithStatus is the metadata of the state as it is sent: the metadata itself when the segment lookups were healthy or there was none, else the metadata with MetadataSegmentStatus set. The map is the one that the evaluation made for this state (the engine clones the metadata of the flag for each evaluation, see constructMetadata), so the key is written into it: no second copy. A state that is built from a map that is shared must not be given a status.