ldhooks

package
v7.6.2 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: Apache-2.0 Imports: 4 Imported by: 1

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

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.

func (EvaluationSeriesData) Get

func (b EvaluationSeriesData) Get(key string) (value any, ok bool)

Get gets the value associated with the given key. If there is no value, then ok will be false.

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

Build builds an EvaluationSeriesData based on the contents of the builder.

func (*EvaluationSeriesDataBuilder) Merge

Merge copies the keys and values from the given map to the builder.

func (*EvaluationSeriesDataBuilder) Set

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.

func (Metadata) Name

func (m Metadata) Name() string

Name gets the name of the hook implementation.

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

AfterEvaluation is a default implementation of the AfterEvaluation stage.

func (Unimplemented) BeforeEvaluation

BeforeEvaluation is a default implementation of the BeforeEvaluation stage.

Jump to

Keyboard shortcuts

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