toggle

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	TargetingKey     string           `json:"targetingKey,omitempty"`
	IPAddress        string           `json:"ipAddress,omitempty"`
	CustomAttributes CustomAttributes `json:"customAttributes,omitempty"`
	User             *User            `json:"user,omitempty"`
}

Context represents the evaluation context for feature toggle evaluation

type CustomAttributes

type CustomAttributes map[string]interface{}

CustomAttributes represents custom key-value pairs for evaluation context

type Evaluation

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

Evaluation represents a single toggle evaluation result

type EvaluationResponse

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

EvaluationResponse represents the response from the toggle evaluation API

type Option

type Option func(*Options)

Option is a functional option for configuring the Toggle client

func WithApplicationID

func WithApplicationID(id string) Option

WithApplicationID sets the application ID for toggle evaluation

func WithDefaultContext

func WithDefaultContext(ctx *Context) Option

WithDefaultContext sets the default evaluation context

func WithDefaultTargetingKey

func WithDefaultTargetingKey(key string) Option

WithDefaultTargetingKey sets the default targeting key

func WithEnvironment

func WithEnvironment(env string) Option

WithEnvironment sets the environment (e.g., "development", "production")

func WithHorizonURLs

func WithHorizonURLs(urls []string) Option

WithHorizonURLs sets custom Horizon API URLs

func WithPublicAPIKey

func WithPublicAPIKey(key string) Option

WithPublicAPIKey sets the public API key for authentication

type Options

type Options struct {
	PublicAPIKey        string
	ApplicationID       string
	Environment         string
	DefaultContext      *Context
	HorizonURLs         []string
	DefaultTargetingKey string
}

Options represents configuration options for the Toggle client

type Toggle

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

Toggle is the client for feature flag management

func New

func New(options ...Option) (*Toggle, error)

New creates a new Toggle client with functional options

func (*Toggle) Get

func (t *Toggle) Get(ctx context.Context, toggleKey string, defaultValue interface{}, contextOverride *Context) (interface{}, error)

Get retrieves a toggle value with generic type support

func (*Toggle) GetBoolean

func (t *Toggle) GetBoolean(ctx context.Context, toggleKey string, defaultValue bool, contextOverride *Context) bool

GetBoolean retrieves a boolean toggle value

func (*Toggle) GetNumber

func (t *Toggle) GetNumber(ctx context.Context, toggleKey string, defaultValue float64, contextOverride *Context) float64

GetNumber retrieves a number toggle value (returns float64)

func (*Toggle) GetObject

func (t *Toggle) GetObject(ctx context.Context, toggleKey string, defaultValue map[string]interface{}, contextOverride *Context) map[string]interface{}

GetObject retrieves an object toggle value

func (*Toggle) GetString

func (t *Toggle) GetString(ctx context.Context, toggleKey string, defaultValue string, contextOverride *Context) string

GetString retrieves a string toggle value

func (*Toggle) SetErrorHandler

func (t *Toggle) SetErrorHandler(handler func(error))

SetErrorHandler sets a custom error handler function

type User

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

User represents user information for evaluation context

Jump to

Keyboard shortcuts

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