flagsmith

package module
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2023 License: BSD-3-Clause Imports: 16 Imported by: 1

README

Go GoReportCard GoDoc

Flagsmith Go SDK

Flagsmith allows you to manage feature flags and remote config across multiple projects, environments and organisations.

This is the SDK for go for https://flagsmith.com/.

Adding to your project

For full documentation visit https://docs.flagsmith.com/clients/server-side.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Getting Help

If you encounter a bug or feature request we would like to hear about it. Before you submit an issue please search existing issues in order to prevent duplicates.

Get in touch

If you have any questions about our projects you can email support@flagsmith.com.

Documentation

Index

Constants

View Source
const (
	// Number of seconds to wait for a request to
	// complete before terminating the request
	DefaultTimeout = 10 * time.Second

	// Default base URL for the API
	DefaultBaseURL = "https://edge.api.flagsmith.com/api/v1/"
)
View Source
const AnalyticsEndpoint = "analytics/flags/"
View Source
const AnalyticsTimerInMilli = 10 * 1000

Variables

This section is empty.

Functions

This section is empty.

Types

type AnalyticsProcessor

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

func NewAnalyticsProcessor

func NewAnalyticsProcessor(ctx context.Context, client *resty.Client, baseURL string, timerInMilli *int, log Logger) *AnalyticsProcessor

func (*AnalyticsProcessor) Flush

func (a *AnalyticsProcessor) Flush(ctx context.Context)

func (*AnalyticsProcessor) TrackFeature

func (a *AnalyticsProcessor) TrackFeature(featureName string)

type Client

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

Client provides various methods to query Flagsmith API

func NewClient

func NewClient(apiKey string, options ...Option) *Client

NewClient creates instance of Client with given configuration

func (*Client) BulkIdentify added in v2.1.0

func (c *Client) BulkIdentify(batch []*IdentityTraits) error

BulkIdentify can be used to create/overwrite identities(with traits) in bulk NOTE: This method only works with Edge API endpoint

func (*Client) GeIdentitySegments

func (c *Client) GeIdentitySegments(identifier string, traits []*Trait) ([]*segments.SegmentModel, error)

Returns an array of segments that the given identity is part of

func (*Client) GetEnvironmentFlags

func (c *Client) GetEnvironmentFlags() (Flags, error)

Returns `Flags` struct holding all the flags for the current environment

func (*Client) GetEnvironmentFlagsFromAPI

func (c *Client) GetEnvironmentFlagsFromAPI(ctx context.Context) (Flags, error)

func (*Client) GetEnvironmentFlagsFromDocument

func (c *Client) GetEnvironmentFlagsFromDocument(ctx context.Context, env *environments.EnvironmentModel) (Flags, error)

func (*Client) GetIdentityFlags

func (c *Client) GetIdentityFlags(identifier string, traits []*Trait) (Flags, error)

Returns `Flags` struct holding all the flags for the current environment for a given identity. Will also upsert all traits to the Flagsmith API for future evaluations. Providing a trait with a value of nil will remove the trait from the identity if it exists.

func (*Client) GetIdentityFlagsFromAPI

func (c *Client) GetIdentityFlagsFromAPI(ctx context.Context, identifier string, traits []*Trait) (Flags, error)

func (*Client) GetIdentityFlagsFromDocument

func (c *Client) GetIdentityFlagsFromDocument(ctx context.Context, env *environments.EnvironmentModel, identifier string, traits []*Trait) (Flags, error)

func (*Client) UpdateEnvironment

func (c *Client) UpdateEnvironment(ctx context.Context) error

type Flag

type Flag struct {
	Enabled     bool
	Value       interface{}
	IsDefault   bool
	FeatureID   int
	FeatureName string
}

type Flags

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

func (*Flags) AllFlags

func (f *Flags) AllFlags() []Flag

Returns an array of all flag objects

func (*Flags) GetFeatureValue

func (f *Flags) GetFeatureValue(featureName string) (interface{}, error)

Returns the value of a particular flag

func (*Flags) GetFlag

func (f *Flags) GetFlag(featureName string) (Flag, error)

Returns a specific flag given the name of the feature

func (*Flags) IsFeatureEnabled

func (f *Flags) IsFeatureEnabled(featureName string) (bool, error)

Returns a boolean indicating whether a particular flag is enabled

type FlagsmithAPIError

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

func (FlagsmithAPIError) Error

func (e FlagsmithAPIError) Error() string

type FlagsmithClientError

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

func (FlagsmithClientError) Error

func (e FlagsmithClientError) Error() string

type IdentityTraits added in v2.1.0

type IdentityTraits struct {
	Identifier string   `json:"identifier"`
	Traits     []*Trait `json:"traits"`
}

type Logger added in v2.3.0

type Logger interface {
	// Errorf logs an error message with the given format and arguments.
	Errorf(format string, v ...interface{})

	// Warnf logs a warning message with the given format and arguments.
	Warnf(format string, v ...interface{})

	// Debugf logs a debug message with the given format and arguments.
	Debugf(format string, v ...interface{})
}

Logger is the interface used for logging by flagsmith client. This interface defines the methods that a logger implementation must implement. It is used to abstract logging and enable clients to use any logger implementation they want.

type Option

type Option func(c *Client)

func WithAnalytics

func WithAnalytics() Option

func WithBaseURL

func WithBaseURL(url string) Option

func WithContext

func WithContext(ctx context.Context) Option

func WithCustomHeaders

func WithCustomHeaders(headers map[string]string) Option

func WithDefaultHandler

func WithDefaultHandler(handler func(string) Flag) Option

func WithEnvironmentRefreshInterval

func WithEnvironmentRefreshInterval(interval time.Duration) Option

func WithLocalEvaluation

func WithLocalEvaluation() Option

func WithLogger added in v2.3.0

func WithLogger(logger Logger) Option

Allows the client to use any logger that implements the `Logger` interface

func WithProxy added in v2.3.0

func WithProxy(proxyURL string) Option

WithProxy returns an Option function that sets the proxy(to be used by internal resty client). The proxyURL argument is a string representing the URL of the proxy server to use, e.g. "http://proxy.example.com:8080".

func WithRemoteEvaluation

func WithRemoteEvaluation() Option

func WithRequestTimeout

func WithRequestTimeout(timeout time.Duration) Option

func WithRetries

func WithRetries(count int, waitTime time.Duration) Option

type Trait

type Trait struct {
	TraitKey   string      `json:"trait_key"`
	TraitValue interface{} `json:"trait_value"`
}

func (*Trait) ToTraitModel

func (t *Trait) ToTraitModel() *traits.TraitModel

Jump to

Keyboard shortcuts

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