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 ¶
- type EvaluationSeries
- type EvaluationSeriesContext
- type EvaluationSeriesData
- type EvaluationSeriesDataBuilder
- type Hook
- type HookMetadataOption
- type Metadata
- type TrackSeries
- type TrackSeriesContext
- type Unimplemented
- func (h Unimplemented) AfterEvaluation(_ context.Context, _ EvaluationSeriesContext, data EvaluationSeriesData, ...) (EvaluationSeriesData, error)
- func (h Unimplemented) AfterTrack(_ context.Context, _ TrackSeriesContext) error
- func (h Unimplemented) BeforeEvaluation(_ context.Context, _ EvaluationSeriesContext, data EvaluationSeriesData) (EvaluationSeriesData, error)
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, environmentID ldvalue.OptionalString, ) 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) EnvironmentID ¶ added in v7.13.0
func (c EvaluationSeriesContext) EnvironmentID() ldvalue.OptionalString
EnvironmentID gets the ID of the environment where the flag is being evaluated.
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
TrackSeries
}
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 TrackSeries ¶ added in v7.12.0
type TrackSeries interface {
// AfterTrack is called during the execution of a track Method.
AfterTrack(
ctx context.Context,
seriesContext TrackSeriesContext,
) error
}
The TrackSeries is composed of stages, methods that are called during the tracking of events.
type TrackSeriesContext ¶ added in v7.12.0
type TrackSeriesContext struct {
// contains filtered or unexported fields
}
TrackSeriesContext contains contextual information for the execution of stages in the evaluation series.
func NewTrackSeriesContext ¶ added in v7.12.0
func NewTrackSeriesContext( context ldcontext.Context, key string, metricValue *float64, data ldvalue.Value, environmentID ldvalue.OptionalString, ) TrackSeriesContext
NewTrackSeriesContext create a new TrackSeriesContext. Hook implementations do not need to use this function.
func (TrackSeriesContext) Context ¶ added in v7.12.0
func (c TrackSeriesContext) Context() ldcontext.Context
Context gets the evaluation context the event is being tracked for.
func (TrackSeriesContext) Data ¶ added in v7.12.0
func (c TrackSeriesContext) Data() ldvalue.Value
Data gets any application-specified data associated with track call.
func (TrackSeriesContext) EnvironmentID ¶ added in v7.13.0
func (c TrackSeriesContext) EnvironmentID() ldvalue.OptionalString
EnvironmentID gets the ID of the environment where the event is being tracked.
func (TrackSeriesContext) Key ¶ added in v7.12.0
func (c TrackSeriesContext) Key() string
Key gets the key associated with the track call.
func (TrackSeriesContext) MetricValue ¶ added in v7.12.0
func (c TrackSeriesContext) MetricValue() *float64
MetricValue gets the metric value associated with the track call.
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) AfterTrack ¶ added in v7.12.0
func (h Unimplemented) AfterTrack( _ context.Context, _ TrackSeriesContext, ) error
AfterTrack is a default implementation of the AfterTrack stage.
func (Unimplemented) BeforeEvaluation ¶
func (h Unimplemented) BeforeEvaluation( _ context.Context, _ EvaluationSeriesContext, data EvaluationSeriesData, ) (EvaluationSeriesData, error)
BeforeEvaluation is a default implementation of the BeforeEvaluation stage.