Documentation ¶
Overview ¶
Package ldhooks allows for writing extensions to the LaunchDarkly client functionality for purposes such as telemetry.
A developer does not need to use this package in the typical operation of the LaunchDarkly SDK.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EvaluationSeries ¶
type EvaluationSeries interface { // BeforeEvaluation is called during the execution of a variation Method before the flag value has been determined. // The Method returns EvaluationSeriesData that will be passed to the next stage in the evaluation // series. // // The EvaluationSeriesData returned should always contain the previous data as well as any new data which is // required for subsequent stage execution. BeforeEvaluation( ctx context.Context, seriesContext EvaluationSeriesContext, data EvaluationSeriesData, ) (EvaluationSeriesData, error) // AfterEvaluation is called during the execution of the variation Method after the flag value has been determined. // The Method returns EvaluationSeriesData that will be passed to the next stage in the evaluation // series. // // The EvaluationSeriesData returned should always contain the previous data as well as any new data which is // required for subsequent stage execution. AfterEvaluation(ctx context.Context, seriesContext EvaluationSeriesContext, data EvaluationSeriesData, detail ldreason.EvaluationDetail, ) (EvaluationSeriesData, error) }
The EvaluationSeries is composed of stages, methods that are called during the evaluation of flags.
type EvaluationSeriesContext ¶
type EvaluationSeriesContext struct {
// contains filtered or unexported fields
}
EvaluationSeriesContext contains contextual information for the execution of stages in the evaluation series.
func NewEvaluationSeriesContext ¶
func NewEvaluationSeriesContext(flagKey string, evalContext ldcontext.Context, defaultValue ldvalue.Value, method string) EvaluationSeriesContext
NewEvaluationSeriesContext create a new EvaluationSeriesContext. Hook implementations do not need to use this function.
func (EvaluationSeriesContext) Context ¶
func (c EvaluationSeriesContext) Context() ldcontext.Context
Context gets the evaluation context the flag is being evaluated for.
func (EvaluationSeriesContext) DefaultValue ¶
func (c EvaluationSeriesContext) DefaultValue() ldvalue.Value
DefaultValue gets the default value for the evaluation.
func (EvaluationSeriesContext) FlagKey ¶
func (c EvaluationSeriesContext) FlagKey() string
FlagKey gets the key of the flag being evaluated.
func (EvaluationSeriesContext) Method ¶
func (c EvaluationSeriesContext) Method() string
Method gets a string represent of the LDClient method being executed.
type EvaluationSeriesData ¶
type EvaluationSeriesData struct {
// contains filtered or unexported fields
}
EvaluationSeriesData is an immutable data type used for passing implementation-specific data between stages in the evaluation series.
func EmptyEvaluationSeriesData ¶
func EmptyEvaluationSeriesData() EvaluationSeriesData
EmptyEvaluationSeriesData returns empty series data. This function is not intended for use by hook implementors. Hook implementations should always use NewEvaluationSeriesBuilder.
func (EvaluationSeriesData) AsAnyMap ¶
func (b EvaluationSeriesData) AsAnyMap() map[string]any
AsAnyMap returns a copy of the contents of the series data as a map.
type EvaluationSeriesDataBuilder ¶
type EvaluationSeriesDataBuilder struct {
// contains filtered or unexported fields
}
EvaluationSeriesDataBuilder should be used by hook implementers to append data
func NewEvaluationSeriesBuilder ¶
func NewEvaluationSeriesBuilder(data EvaluationSeriesData) *EvaluationSeriesDataBuilder
NewEvaluationSeriesBuilder creates an EvaluationSeriesDataBuilder based on the provided EvaluationSeriesData.
func(h MyHook) BeforeEvaluation(seriesContext EvaluationSeriesContext, data EvaluationSeriesData) EvaluationSeriesData { // Some hook functionality. return NewEvaluationSeriesBuilder(data).Set("my-key", myValue).Build() }
func (*EvaluationSeriesDataBuilder) Build ¶
func (b *EvaluationSeriesDataBuilder) Build() EvaluationSeriesData
Build builds an EvaluationSeriesData based on the contents of the builder.
func (*EvaluationSeriesDataBuilder) Merge ¶
func (b *EvaluationSeriesDataBuilder) Merge(newValues map[string]any) *EvaluationSeriesDataBuilder
Merge copies the keys and values from the given map to the builder.
func (*EvaluationSeriesDataBuilder) Set ¶
func (b *EvaluationSeriesDataBuilder) Set(key string, value any) *EvaluationSeriesDataBuilder
Set sets the given key to the given value.
type Hook ¶
type Hook interface { Metadata() Metadata EvaluationSeries }
A Hook is used to extend the functionality of the SDK.
In order to avoid implementing unused methods, as well as easing maintenance of compatibility, implementors should compose the `Unimplemented`.
type MyHook struct { ldhooks.Unimplemented }
type HookMetadataOption ¶
type HookMetadataOption func(hook *Metadata)
HookMetadataOption represents a functional means of setting additional, optional, attributes of the Metadata.
type Metadata ¶
type Metadata struct {
// contains filtered or unexported fields
}
Metadata contains information about a specific hook implementation.
func NewMetadata ¶
func NewMetadata(name string, opts ...HookMetadataOption) Metadata
NewMetadata creates Metadata with the provided name.
type Unimplemented ¶
type Unimplemented struct { }
Unimplemented implements all Hook methods with empty functions. Hook implementors should use this to avoid having to implement empty methods and to ease updates when the Hook interface is extended.
type MyHook struct { ldhooks.Unimplemented }
The hook should implement at least one stage/handler as well as the Metadata function.
func (Unimplemented) AfterEvaluation ¶
func (h Unimplemented) AfterEvaluation( _ context.Context, _ EvaluationSeriesContext, data EvaluationSeriesData, _ ldreason.EvaluationDetail, ) (EvaluationSeriesData, error)
AfterEvaluation is a default implementation of the AfterEvaluation stage.
func (Unimplemented) BeforeEvaluation ¶
func (h Unimplemented) BeforeEvaluation( _ context.Context, _ EvaluationSeriesContext, data EvaluationSeriesData, ) (EvaluationSeriesData, error)
BeforeEvaluation is a default implementation of the BeforeEvaluation stage.