flagstate

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package flagstate builds the state of a flag evaluation returned by the all flags and flag evaluation APIs.

Index

Constants

View Source
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

func WithSegmentStatus(metadata map[string]any, status segment.Status) map[string]any

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) AddFlag

func (a *AllFlags) AddFlag(flagKey string, state *FlagState)

AddFlag is adding a flag in the list for the specific user.

func (*AllFlags) GetFlags

func (a *AllFlags) GetFlags() map[string]FlagState

GetFlags returns the state of every flag by name.

func (*AllFlags) IsValid

func (a *AllFlags) IsValid() bool

IsValid is a getter to know if the AllFlags object is valid.

func (AllFlags) MarshalJSON

func (a AllFlags) MarshalJSON() ([]byte, error)

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

func (f *FlagState) MetadataWithStatus() map[string]any

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.

Jump to

Keyboard shortcuts

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