toggle

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2025 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultHorizonURL = "https://dev-horizon.hyphen.ai"
	DefaultCacheTTL   = 30
)

Variables

View Source
var (
	ErrMissingApplication       = errors.New("application is required")
	ErrMissingEnvironment       = errors.New("environment is required")
	ErrMissingPublicKey         = errors.New("public key is required")
	ErrMissingTargetKey         = errors.New("targeting key is required")
	ErrInvalidFlagType          = errors.New("invalid flag type")
	ErrFlagNotFound             = errors.New("flag not found")
	ErrInvalidEnvironmentFormat = errors.New("invalid environment format. Must be either a project environment ID (starting with \"pevr_\") or a valid alternateId (1-25 characters, lowercase letters, numbers, hyphens, and underscores, not containing the word \"environments\")")
)

Functions

This section is empty.

Types

type CacheConfig added in v1.0.0

type CacheConfig struct {
	TTL    time.Duration
	KeyGen func(ctx EvaluationContext) string
}

type Client added in v1.0.0

type Client struct {
	// contains filtered or unexported fields
}

func (*Client) Evaluate added in v1.0.0

func (c *Client) Evaluate(ctx EvaluationContext) (*Response, error)

func (*Client) SendTelemetry added in v1.0.0

func (c *Client) SendTelemetry(payload TelemetryPayload) error

type ClientInterface added in v1.0.0

type ClientInterface interface {
	Evaluate(ctx EvaluationContext) (*Response, error)
	SendTelemetry(payload TelemetryPayload) error
}

type Config added in v1.0.0

type Config struct {
	PublicKey   string
	Application string
	Environment string
	HorizonUrls []string
	EnableUsage *bool
	Cache       *CacheConfig
}

type Evaluation added in v1.0.0

type Evaluation struct {
	Key    string      `json:"key"`
	Value  interface{} `json:"value"`
	Type   string      `json:"type"`
	Reason string      `json:"reason,omitempty"`
	Error  string      `json:"error,omitempty"`
}

type EvaluationContext added in v1.0.0

type EvaluationContext struct {
	TargetingKey     string                 `json:"targetingKey"`
	IPAddress        string                 `json:"ipAddress,omitempty"`
	Application      string                 `json:"application"`
	Environment      string                 `json:"environment"`
	User             *User                  `json:"user,omitempty"`
	CustomAttributes map[string]interface{} `json:"customAttributes,omitempty"`
}

type HorizonConfig added in v1.0.0

type HorizonConfig struct {
	URL string
}

type HorizonEndpoints added in v1.0.0

type HorizonEndpoints struct {
	Evaluate  string
	Telemetry string
}

type Provider added in v1.0.0

type Provider struct {
	// contains filtered or unexported fields
}

func NewProvider added in v1.0.0

func NewProvider(config Config) (*Provider, error)

func (*Provider) BooleanEvaluation added in v1.0.0

func (p *Provider) BooleanEvaluation(ctx context.Context, flag string, defaultValue bool, evalCtx openfeature.FlattenedContext) openfeature.BoolResolutionDetail

func (*Provider) FloatEvaluation added in v1.0.0

func (p *Provider) FloatEvaluation(ctx context.Context, flag string, defaultValue float64, evalCtx openfeature.FlattenedContext) openfeature.FloatResolutionDetail

func (*Provider) Hooks added in v1.0.0

func (p *Provider) Hooks() []openfeature.Hook

func (*Provider) IntEvaluation added in v1.0.0

func (p *Provider) IntEvaluation(ctx context.Context, flag string, defaultValue int64, evalCtx openfeature.FlattenedContext) openfeature.IntResolutionDetail

func (*Provider) Metadata added in v1.0.0

func (p *Provider) Metadata() openfeature.Metadata

func (*Provider) ObjectEvaluation added in v1.0.0

func (p *Provider) ObjectEvaluation(ctx context.Context, flag string, defaultValue interface{}, evalCtx openfeature.FlattenedContext) openfeature.InterfaceResolutionDetail

func (*Provider) StringEvaluation added in v1.0.0

func (p *Provider) StringEvaluation(
	ctx context.Context,
	flag string,
	defaultValue string,
	evalCtx openfeature.FlattenedContext,
) openfeature.StringResolutionDetail

type ProviderHook added in v1.0.0

type ProviderHook struct {
	openfeature.UnimplementedHook
	// contains filtered or unexported fields
}

func NewProviderHook added in v1.0.0

func NewProviderHook(provider *Provider) *ProviderHook

func (*ProviderHook) After added in v1.0.0

func (*ProviderHook) Before added in v1.0.0

func (*ProviderHook) Error added in v1.0.0

func (h *ProviderHook) Error(ctx context.Context, hookContext openfeature.HookContext, err error, hookHints openfeature.HookHints)

type Response added in v1.0.0

type Response struct {
	Toggles map[string]Evaluation `json:"toggles"`
}

type TelemetryPayload added in v1.0.0

type TelemetryPayload struct {
	Context EvaluationContext `json:"context"`
	Data    struct {
		Toggle Evaluation `json:"toggle"`
	} `json:"data"`
}

type User added in v1.0.0

type User struct {
	ID               string                 `json:"id"`
	Email            string                 `json:"email,omitempty"`
	Name             string                 `json:"name,omitempty"`
	CustomAttributes map[string]interface{} `json:"customAttributes,omitempty"`
}

Jump to

Keyboard shortcuts

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