Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNullEvaluations = errors.New("the evaluations response was null")
ErrNullEvaluations is returned by ParseEvaluations for a JSON null body.
var ErrShutDown = errors.New("the Octopus feature provider has been shut down and can't be initialized again; create a new provider instead")
ErrShutDown is returned by FeatureFlagEvaluatorCache.Start once the cache has been shut down.
Functions ¶
This section is empty.
Types ¶
type ClientSideCondition ¶
type ClientSideCondition struct {
// contains filtered or unexported fields
}
ClientSideCondition is one condition of a ClientSideRule, decoded by its type.
func (*ClientSideCondition) UnmarshalJSON ¶
func (c *ClientSideCondition) UnmarshalJSON(data []byte) error
UnmarshalJSON reads type first and decodes only the fields that type needs. An unrecognised type has none of its fields decoded, so a condition introduced by a newer server can't fail an older client's response.
type ClientSideRule ¶
type ClientSideRule struct {
Name *string `json:"name"`
Conditions []*ClientSideCondition `json:"conditions"`
}
ClientSideRule is a named rule the server left for the client to evaluate. It matches when every one of its conditions matches.
type EvaluationResponse ¶
type EvaluationResponse struct {
Evaluations []ServerSideEvaluation
ContentHash []byte
}
EvaluationResponse is one v4 evaluations response: its flags, and the content hash the check endpoint compares against to detect changes.
type FeatureFlagApiClient ¶
type FeatureFlagApiClient struct {
// contains filtered or unexported fields
}
FeatureFlagApiClient retrieves feature flag evaluations from the Octopus feature flags service.
func NewFeatureFlagApiClient ¶
func NewFeatureFlagApiClient(options FeatureFlagApiClientOptions) *FeatureFlagApiClient
NewFeatureFlagApiClient returns a client for options. HttpClient must not be nil.
func (*FeatureFlagApiClient) GetServerSideEvaluations ¶
func (c *FeatureFlagApiClient) GetServerSideEvaluations(ctx context.Context) (EvaluationResponse, error)
GetServerSideEvaluations fetches the current v4 evaluations. Each request is bounded by RequestTimeout as well as ctx.
func (*FeatureFlagApiClient) HaveFeaturesChanged ¶
func (c *FeatureFlagApiClient) HaveFeaturesChanged(ctx context.Context, contentHash []byte) (bool, error)
HaveFeaturesChanged reports whether the service's evaluations no longer match contentHash. An empty contentHash means nothing has been fetched yet, so it reports a change without asking. The request is bounded by RequestTimeout as well as ctx.
type FeatureFlagApiClientOptions ¶
type FeatureFlagApiClientOptions struct {
ServerUri string
ClientIdentifier string
ProductName string
ProductVersion string // sent only when not empty
ProviderVersion string
ReleaseVersionOverride string // sent only when not empty
RequestTimeout time.Duration
HttpClient *http.Client
}
FeatureFlagApiClientOptions configures a FeatureFlagApiClient.
type FeatureFlagEvaluator ¶
type FeatureFlagEvaluator struct {
// contains filtered or unexported fields
}
FeatureFlagEvaluator resolves flags from one evaluation response. It is safe for concurrent use.
func EmptyFeatureFlagEvaluator ¶
func EmptyFeatureFlagEvaluator(logger *slog.Logger) *FeatureFlagEvaluator
EmptyFeatureFlagEvaluator returns an evaluator with no flags, for use before a response has been fetched. Every evaluation returns FLAG_NOT_FOUND.
func NewFeatureFlagEvaluator ¶
func NewFeatureFlagEvaluator(response EvaluationResponse, logger *slog.Logger) *FeatureFlagEvaluator
NewFeatureFlagEvaluator returns an evaluator for response. The logger must not be nil.
func (*FeatureFlagEvaluator) ContentHash ¶
func (e *FeatureFlagEvaluator) ContentHash() []byte
ContentHash returns the content hash of the response the evaluator was built from.
func (*FeatureFlagEvaluator) Evaluate ¶
func (e *FeatureFlagEvaluator) Evaluate(slug string, defaultValue bool, flatCtx openfeature.FlattenedContext) openfeature.BoolResolutionDetail
Evaluate resolves the flag with the given slug. On any error it returns defaultValue alongside the error. A missing slug logs a warning the first time it is asked for, ignoring case.
func (*FeatureFlagEvaluator) FindEvaluationBySlug ¶
func (e *FeatureFlagEvaluator) FindEvaluationBySlug(slug string) (ServerSideEvaluation, bool)
FindEvaluationBySlug returns the first flag whose slug matches, ignoring case.
type FeatureFlagEvaluatorCache ¶
type FeatureFlagEvaluatorCache struct {
// contains filtered or unexported fields
}
FeatureFlagEvaluatorCache holds the evaluator the provider evaluates against, and keeps it current by polling for changes. It starts with the empty evaluator, so evaluations return FLAG_NOT_FOUND until a manifest has been fetched.
func NewFeatureFlagEvaluatorCache ¶
func NewFeatureFlagEvaluatorCache(client *FeatureFlagApiClient, cacheDuration time.Duration, logger *slog.Logger) *FeatureFlagEvaluatorCache
NewFeatureFlagEvaluatorCache returns a cache that fetches with client and checks for changes every cacheDuration. The logger must not be nil.
func (*FeatureFlagEvaluatorCache) GetEvaluator ¶
func (c *FeatureFlagEvaluatorCache) GetEvaluator() *FeatureFlagEvaluator
GetEvaluator returns the current evaluator.
func (*FeatureFlagEvaluatorCache) Shutdown ¶
func (c *FeatureFlagEvaluatorCache) Shutdown(ctx context.Context) error
Shutdown stops polling and cancels any request in flight, even if ctx is already done. It then waits for the poller to exit, returning ctx's error if ctx ends first. It's safe to call more than once, even before Start. The cache keeps serving its last evaluator, but can't be started again.
func (*FeatureFlagEvaluatorCache) Start ¶
func (c *FeatureFlagEvaluatorCache) Start(ctx context.Context) error
Start fetches the manifest and then polls for changes until Shutdown. A failed fetch is logged and doesn't stop polling, and the cache keeps serving the evaluator it has. A second call while the cache is running starts nothing new: it waits for the first fetch to finish, or for ctx to end. After Shutdown, Start returns ErrShutDown.
type RejectedResponseError ¶
RejectedResponseError is returned when the service responds, but not with a usable manifest. The cache logs it as a warning during init, and as an error when a refresh fails. Other failures are always errors.
func (*RejectedResponseError) Error ¶
func (e *RejectedResponseError) Error() string
type ServerSideEvaluation ¶
type ServerSideEvaluation struct {
Slug string `json:"slug"`
Value *bool `json:"value"`
Reason *string `json:"reason"`
EvaluationKey *string `json:"evaluationKey"`
Rules []*ClientSideRule `json:"rules"`
}
ServerSideEvaluation is one flag from the v4 evaluations endpoint, either resolved by the server (Value and Reason) or deferred to the client (EvaluationKey and Rules). Pointers and a nil Rules slice let a missing field be told apart from false, "" or [].
func ParseEvaluations ¶
func ParseEvaluations(body []byte) ([]ServerSideEvaluation, error)
ParseEvaluations decodes the body of a v4 evaluations response. Null entries and entries without a slug are dropped, since no lookup can match them. A wrong-typed field fails the whole response.
func (ServerSideEvaluation) Evaluate ¶
func (e ServerSideEvaluation) Evaluate(flatCtx openfeature.FlattenedContext) (bool, string, error)
Evaluate resolves the flag, returning its value and reason. A flag deferred to the client is enabled when any of its rules matches. A malformed flag returns a PARSE_ERROR openfeature.ResolutionError.