configcat

package module
v4.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package configcat contains the Golang SDK for ConfigCat (https://configcat.com)

Index

Constants

View Source
const (
	// Fetched indicates that a new configuration was fetched.
	Fetched fetchStatus = 0
	// NotModified indicates that the current configuration is not modified.
	NotModified fetchStatus = 1
	// Failure indicates that the current configuration fetch is failed.
	Failure fetchStatus = 2
)
View Source
const (
	LogLevelPanic = LogLevel(logrus.PanicLevel)
	LogLevelFatal = LogLevel(logrus.FatalLevel)
	LogLevelError = LogLevel(logrus.ErrorLevel)
	LogLevelWarn  = LogLevel(logrus.WarnLevel)
	LogLevelInfo  = LogLevel(logrus.InfoLevel)
	LogLevelDebug = LogLevel(logrus.DebugLevel)
	LogLevelTrace = LogLevel(logrus.TraceLevel)
)

Define the logrus log levels

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is an object for handling configurations provided by ConfigCat.

func NewClient

func NewClient(apiKey string) *Client

NewClient initializes a new ConfigCat Client with the default configuration. The api key parameter is mandatory.

func NewCustomClient

func NewCustomClient(apiKey string, config ClientConfig) *Client

NewCustomClient initializes a new ConfigCat Client with advanced configuration. The api key parameter is mandatory.

func (*Client) Close

func (client *Client) Close()

Close shuts down the client, after closing, it shouldn't be used

func (*Client) GetAllKeys

func (client *Client) GetAllKeys() ([]string, error)

GetAllKeys retrieves all the setting keys.

func (*Client) GetAllKeysAsync

func (client *Client) GetAllKeysAsync(completion func(result []string, err error))

GetAllKeysAsync retrieves all the setting keys asynchronously.

func (*Client) GetValue

func (client *Client) GetValue(key string, defaultValue interface{}) interface{}

GetValue returns a value synchronously as interface{} from the configuration identified by the given key.

func (*Client) GetValueAsync

func (client *Client) GetValueAsync(key string, defaultValue interface{}, completion func(result interface{}))

GetValueAsync reads and sends a value asynchronously to a callback function as interface{} from the configuration identified by the given key.

func (*Client) GetValueAsyncForUser

func (client *Client) GetValueAsyncForUser(key string, defaultValue interface{}, user *User, completion func(result interface{}))

GetValueAsyncForUser reads and sends a value asynchronously to a callback function as interface{} from the configuration identified by the given key. Optional user argument can be passed to identify the caller.

func (*Client) GetValueForUser

func (client *Client) GetValueForUser(key string, defaultValue interface{}, user *User) interface{}

GetValueForUser returns a value synchronously as interface{} from the configuration identified by the given key. Optional user argument can be passed to identify the caller.

func (*Client) Refresh

func (client *Client) Refresh()

Refresh initiates a force refresh synchronously on the cached configuration.

func (*Client) RefreshAsync

func (client *Client) RefreshAsync(completion func())

RefreshAsync initiates a force refresh asynchronously on the cached configuration.

type ClientConfig

type ClientConfig struct {
	// Base logger used to create new loggers
	Logger Logger
	// The custom cache implementation used to store the configuration.
	Cache ConfigCache
	// The maximum time how long at most the synchronous calls (e.g. client.get(...)) should block the caller.
	// If it's 0 then the caller will be blocked in case of sync calls, until the operation succeeds or fails.
	MaxWaitTimeForSyncCalls time.Duration
	// The maximum wait time for a http response.
	HttpTimeout time.Duration
	// The base ConfigCat CDN url.
	BaseUrl string
	// The custom http transport object.
	Transport http.RoundTripper
	// The refresh mode of the cached configuration.
	Mode RefreshMode
}

ClientConfig describes custom configuration options for the Client.

type ConfigCache

type ConfigCache interface {
	// get reads the configuration from the cache.
	Get() (string, error)
	// set writes the configuration into the cache.
	Set(value string) error
}

ConfigCache is a cache API used to make custom cache implementations.

type ConfigParser

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

ConfigParser describes a JSON configuration parser.

func (*ConfigParser) GetAllKeys

func (parser *ConfigParser) GetAllKeys(jsonBody string) ([]string, error)

GetAllKeys retrieves all the setting keys from the given json config.

func (*ConfigParser) Parse

func (parser *ConfigParser) Parse(jsonBody string, key string) (interface{}, error)

Parse converts a json element identified by a key from the given json string into an interface{} value.

func (*ConfigParser) ParseWithUser

func (parser *ConfigParser) ParseWithUser(jsonBody string, key string, user *User) (interface{}, error)

ParseWithUser converts a json element identified by the key from the given json string into an interface{} value. Optional user argument can be passed to identify the caller.

type LogLevel added in v4.0.4

type LogLevel uint32

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Errorf(format string, args ...interface{})

	Debug(args ...interface{})
	Info(args ...interface{})
	Warn(args ...interface{})
	Error(args ...interface{})

	Debugln(args ...interface{})
	Infoln(args ...interface{})
	Warnln(args ...interface{})
	Errorln(args ...interface{})
}

Logger defines the interface this library logs with.

func DefaultLogger

func DefaultLogger(level LogLevel) Logger

DefaultLogger creates the default logger with specified log level (logrus.New()).

type ParseError

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

ParseError describes JSON parsing related errors.

func (*ParseError) Error

func (p *ParseError) Error() string

Error is the error message.

type RefreshMode

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

RefreshMode is a base for refresh mode configurations.

func AutoPoll

func AutoPoll(interval time.Duration) RefreshMode

AutoPoll creates an auto polling refresh mode.

func AutoPollWithChangeListener

func AutoPollWithChangeListener(
	interval time.Duration,
	changeListener func()) RefreshMode

AutoPollWithChangeListener creates an auto polling refresh mode with change listener callback.

func LazyLoad

func LazyLoad(cacheInterval time.Duration, useAsyncRefresh bool) RefreshMode

LazyLoad creates a lazy loading refresh mode.

func ManualPoll

func ManualPoll() RefreshMode

ManualPoll creates a manual loading refresh mode.

type User

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

User is an object containing attributes to properly identify a given user for rollout evaluation.

func NewUser

func NewUser(identifier string) *User

NewUser creates a new user object. The identifier argument is mandatory.

func NewUserWithAdditionalAttributes

func NewUserWithAdditionalAttributes(identifier string, email string, country string, custom map[string]string) *User

NewUserWithAdditionalAttributes creates a new user object with additional attributes. The identifier argument is mandatory.

func (*User) GetAttribute

func (user *User) GetAttribute(key string) string

GetAttribute retrieves a user attribute identified by a key.

Jump to

Keyboard shortcuts

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