statsig

package module
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2022 License: ISC Imports: 21 Imported by: 3

README

Statsig Go Server SDK

tests

The Statsig Go SDK for multi-user, server side environments. If you need a SDK for another language or single user client environment, check out our other SDKs.

Statsig helps you move faster with Feature Gates (Feature Flags) and Dynamic Configs. It also allows you to run A/B tests to validate your new features and understand their impact on your KPIs. If you're new to Statsig, create an account at statsig.com.

Getting Started

Check out our SDK docs to get started.

Testing

Each server SDK is tested at multiple levels - from unit to integration and e2e tests. Our internal e2e test harness runs daily against each server SDK, while unit and integration tests can be seen in the respective github repos of each SDK. The statsig_test.go runs a validation test on local rule/condition evaluation for this SDK against the results in the statsig backend.

Guidelines

Documentation

Overview

Package statsig implements feature gating and a/b testing

Index

Constants

View Source
const (
	InvalidSDKKeyError  string = "Must provide a valid SDK key."
	EmptyUserError      string = "" /* 127-byte string literal not displayed */
	EventBatchSizeError string = "The max number of events supported in one batch is 500. Please reduce the slice size and try again."
)
View Source
const DefaultEndpoint = "https://statsigapi.net/v1"

Variables

This section is empty.

Functions

func CheckGate

func CheckGate(user User, gate string) bool

Checks the value of a Feature Gate for the given user

func CheckGateWithExposureLoggingDisabled added in v1.8.0

func CheckGateWithExposureLoggingDisabled(user User, gate string) bool

Checks the value of a Feature Gate for the given user without logging an exposure event

func Initialize

func Initialize(sdkKey string)

Initializes the global Statsig instance with the given sdkKey

func InitializeWithOptions

func InitializeWithOptions(sdkKey string, options *Options)

Initializes the global Statsig instance with the given sdkKey and options

func LogEvent

func LogEvent(event Event)

Logs an event to the Statsig console

func LogImmediate added in v1.2.0

func LogImmediate(events []Event) (*http.Response, error)

Logs a slice of events to Statsig server immediately

func ManuallyLogConfigExposure added in v1.8.0

func ManuallyLogConfigExposure(user User, config string)

Logs an exposure event for the dynamic config

func ManuallyLogExperimentExposure added in v1.8.0

func ManuallyLogExperimentExposure(user User, experiment string)

Logs an exposure event for the experiment

func ManuallyLogGateExposure added in v1.8.0

func ManuallyLogGateExposure(user User, config string)

Logs an exposure event for the gate

func ManuallyLogLayerParameterExposure added in v1.8.0

func ManuallyLogLayerParameterExposure(user User, layer string, parameter string)

Logs an exposure event for the parameter in the given layer

func OverrideConfig added in v1.3.0

func OverrideConfig(config string, val map[string]interface{})

Override the DynamicConfig value for the given user

func OverrideGate added in v1.3.0

func OverrideGate(gate string, val bool)

Override the value of a Feature Gate for the given user

func Shutdown

func Shutdown()

Cleans up Statsig, persisting any Event Logs and cleanup processes Using any method is undefined after Shutdown() has been called

Types

type Client

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

An instance of a StatsigClient for interfacing with Statsig Feature Gates, Dynamic Configs, Experiments, and Event Logging

func NewClient added in v1.0.0

func NewClient(sdkKey string) *Client

Initializes a Statsig Client with the given sdkKey

func NewClientWithOptions added in v1.0.0

func NewClientWithOptions(sdkKey string, options *Options) *Client

Initializes a Statsig Client with the given sdkKey and options

func (*Client) CheckGate

func (c *Client) CheckGate(user User, gate string) bool

Checks the value of a Feature Gate for the given user

func (*Client) CheckGateWithExposureLoggingDisabled added in v1.8.0

func (c *Client) CheckGateWithExposureLoggingDisabled(user User, gate string) bool

Checks the value of a Feature Gate for the given user without logging an exposure event

func (*Client) GetConfig

func (c *Client) GetConfig(user User, config string) DynamicConfig

Gets the DynamicConfig value for the given user

func (*Client) GetConfigWithExposureLoggingDisabled added in v1.8.0

func (c *Client) GetConfigWithExposureLoggingDisabled(user User, config string) DynamicConfig

Gets the DynamicConfig value for the given user without logging an exposure event

func (*Client) GetExperiment

func (c *Client) GetExperiment(user User, experiment string) DynamicConfig

Gets the DynamicConfig value of an Experiment for the given user

func (*Client) GetExperimentWithExposureLoggingDisabled added in v1.8.0

func (c *Client) GetExperimentWithExposureLoggingDisabled(user User, experiment string) DynamicConfig

Gets the DynamicConfig value of an Experiment for the given user without logging an exposure event

func (*Client) GetLayer added in v1.4.0

func (c *Client) GetLayer(user User, layer string) Layer

Gets the Layer object for the given user

func (*Client) GetLayerWithExposureLoggingDisabled added in v1.8.0

func (c *Client) GetLayerWithExposureLoggingDisabled(user User, layer string) Layer

Gets the Layer object for the given user without logging an exposure event

func (*Client) LogEvent

func (c *Client) LogEvent(event Event)

Logs an event to Statsig for analysis in the Statsig Console

func (*Client) LogImmediate added in v1.2.0

func (c *Client) LogImmediate(events []Event) (*http.Response, error)

func (*Client) ManuallyLogConfigExposure added in v1.8.0

func (c *Client) ManuallyLogConfigExposure(user User, config string)

Logs an exposure event for the config

func (*Client) ManuallyLogExperimentExposure added in v1.8.0

func (c *Client) ManuallyLogExperimentExposure(user User, experiment string)

Logs an exposure event for the experiment

func (*Client) ManuallyLogGateExposure added in v1.8.0

func (c *Client) ManuallyLogGateExposure(user User, gate string)

Logs an exposure event for the dynamic config

func (*Client) ManuallyLogLayerParameterExposure added in v1.8.0

func (c *Client) ManuallyLogLayerParameterExposure(user User, layer string, parameter string)

Logs an exposure event for the parameter in the given layer

func (*Client) OverrideConfig added in v1.3.0

func (c *Client) OverrideConfig(config string, val map[string]interface{})

Override the DynamicConfig value for the given user

func (*Client) OverrideGate added in v1.3.0

func (c *Client) OverrideGate(gate string, val bool)

Override the value of a Feature Gate for the given user

func (*Client) Shutdown

func (c *Client) Shutdown()

Cleans up Statsig, persisting any Event Logs and cleanup processes Using any method is undefined after Shutdown() has been called

type DynamicConfig added in v1.0.0

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

A json blob configured in the Statsig Console

func GetConfig

func GetConfig(user User, config string) DynamicConfig

Gets the DynamicConfig value for the given user

func GetConfigWithExposureLoggingDisabled added in v1.8.0

func GetConfigWithExposureLoggingDisabled(user User, config string) DynamicConfig

Gets the DynamicConfig value for the given user without logging an exposure event

func GetExperiment

func GetExperiment(user User, experiment string) DynamicConfig

Gets the DynamicConfig value of an Experiment for the given user

func GetExperimentWithExposureLoggingDisabled added in v1.8.0

func GetExperimentWithExposureLoggingDisabled(user User, experiment string) DynamicConfig

Gets the DynamicConfig value of an Experiment for the given user without logging an exposure event

func NewConfig added in v1.0.0

func NewConfig(name string, value map[string]interface{}, ruleID string) *DynamicConfig

func (*DynamicConfig) GetBool added in v1.0.0

func (d *DynamicConfig) GetBool(key string, fallback bool) bool

Gets the boolean value at the given key in the DynamicConfig Returns the fallback boolean if the item at the given key is not found or not of type boolean

func (*DynamicConfig) GetMap added in v1.5.0

func (d *DynamicConfig) GetMap(key string, fallback map[string]interface{}) map[string]interface{}

func (*DynamicConfig) GetNumber added in v1.0.0

func (d *DynamicConfig) GetNumber(key string, fallback float64) float64

Gets the float64 value at the given key in the DynamicConfig Returns the fallback float64 if the item at the given key is not found or not of type float64

func (*DynamicConfig) GetSlice added in v1.0.0

func (d *DynamicConfig) GetSlice(key string, fallback []interface{}) []interface{}

Gets the slice value at the given key in the DynamicConfig Returns the fallback slice if the item at the given key is not found or not of type slice

func (*DynamicConfig) GetString added in v1.0.0

func (d *DynamicConfig) GetString(key string, fallback string) string

Gets the string value at the given key in the DynamicConfig Returns the fallback string if the item at the given key is not found or not of type string

type Environment added in v1.0.0

type Environment struct {
	Tier   string            `json:"tier"`
	Params map[string]string `json:"params"`
}

See https://docs.statsig.com/guides/usingEnvironments

type Event added in v1.0.0

type Event struct {
	EventName string            `json:"eventName"`
	User      User              `json:"user"`
	Value     string            `json:"value"`
	Metadata  map[string]string `json:"metadata"`
	Time      int64             `json:"time"`
}

an event to be sent to Statsig for logging and analysis

type IDataAdapter added in v1.8.0

type IDataAdapter interface {
	// contains filtered or unexported methods
}

*

  • An adapter for implementing custom storage of config specs.
  • Can be used to bootstrap Statsig (priority over bootstrapValues if both provided)
  • Also useful for backing up cached data

type Layer added in v1.4.0

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

func GetLayer added in v1.4.0

func GetLayer(user User, layer string) Layer

Gets the Layer object for the given user

func GetLayerWithExposureLoggingDisabled added in v1.8.0

func GetLayerWithExposureLoggingDisabled(user User, layer string) Layer

Gets the Layer object for the given user without logging an exposure event

func NewLayer added in v1.4.0

func NewLayer(name string, value map[string]interface{}, ruleID string, logExposure *func(configBase, string)) *Layer

func (*Layer) GetBool added in v1.4.0

func (d *Layer) GetBool(key string, fallback bool) bool

Gets the boolean value at the given key in the DynamicConfig Returns the fallback boolean if the item at the given key is not found or not of type boolean

func (*Layer) GetMap added in v1.5.0

func (d *Layer) GetMap(key string, fallback map[string]interface{}) map[string]interface{}

func (*Layer) GetNumber added in v1.4.0

func (d *Layer) GetNumber(key string, fallback float64) float64

Gets the float64 value at the given key in the DynamicConfig Returns the fallback float64 if the item at the given key is not found or not of type float64

func (*Layer) GetSlice added in v1.4.0

func (d *Layer) GetSlice(key string, fallback []interface{}) []interface{}

Gets the slice value at the given key in the DynamicConfig Returns the fallback slice if the item at the given key is not found or not of type slice

func (*Layer) GetString added in v1.4.0

func (d *Layer) GetString(key string, fallback string) string

Gets the string value at the given key in the DynamicConfig Returns the fallback string if the item at the given key is not found or not of type string

type Options added in v1.0.0

type Options struct {
	API                  string      `json:"api"`
	Environment          Environment `json:"environment"`
	LocalMode            bool        `json:"localMode"`
	ConfigSyncInterval   time.Duration
	IDListSyncInterval   time.Duration
	LoggingInterval      time.Duration
	LoggingMaxBufferSize int
	BootstrapValues      string
	RulesUpdatedCallback func(rules string, time int64)
	InitTimeout          time.Duration
	DataAdapter          IDataAdapter
}

Advanced options for configuring the Statsig SDK

type User added in v1.0.0

type User struct {
	UserID             string                 `json:"userID"`
	Email              string                 `json:"email"`
	IpAddress          string                 `json:"ip"`
	UserAgent          string                 `json:"userAgent"`
	Country            string                 `json:"country"`
	Locale             string                 `json:"locale"`
	AppVersion         string                 `json:"appVersion"`
	Custom             map[string]interface{} `json:"custom"`
	PrivateAttributes  map[string]interface{} `json:"privateAttributes"`
	StatsigEnvironment map[string]string      `json:"statsigEnvironment"`
	CustomIDs          map[string]string      `json:"customIDs"`
}

User specific attributes for evaluating Feature Gates, Experiments, and DyanmicConfigs

NOTE: UserID is **required** - see https://docs.statsig.com/messages/serverRequiredUserID\ PrivateAttributes are only used for user targeting/grouping in feature gates, dynamic configs, experiments and etc; they are omitted in logs.

Jump to

Keyboard shortcuts

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