devcycle

package module
v2.9.6 Latest Latest
Warning

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

Go to latest
Published: May 1, 2023 License: MIT Imports: 30 Imported by: 3

README

DevCycle Go Server SDK.

This SDK supports both cloud bucketing (requests outbound to https://bucketing-api.devcycle.com) as well as local bucketing (requests to a local bucketing engine self-contained in this SDK).

Installation

go get "github.com/devcyclehq/go-server-sdk/v2"
package main
import "github.com/devcyclehq/go-server-sdk/v2"

Getting Started

    sdkKey := os.Getenv("DVC_SERVER_KEY")
	user := devcycle.DVCUser{UserId: "test"}

	dvcOptions := devcycle.DVCOptions{
		EnableEdgeDB:                 false,
		EnableCloudBucketing:         false,
		EventFlushIntervalMS:         0,
		ConfigPollingIntervalMS:      10 * time.Second,
		RequestTimeout:               10 * time.Second,
		DisableAutomaticEventLogging: false,
		DisableCustomEventLogging:    false,
	}

	client, _ := devcycle.NewDVCClient(sdkKey, &dvcOptions)

Usage

To find usage documentation, visit our docs.

Testing

This SDK is supported by our test harness, a test suite shared between all DevCycle SDKs for consistency.

Native Bucketing Library (Experimental)

This SDK also supports an experimental version of the DevCycle bucketing and segmentation logic built natively in Go. This system is designed as a ultra-high performance alternative to the WASM and Cloud bucketing solutions.

To activate the native bucketing library, include the following build tag for your application:

-tags native_bucketing

This implementation is still under-going active development. Take care when utilizing it in production environments.

Documentation

Overview

* DevCycle Bucketing API * * Documents the DevCycle Bucketing API which provides and API interface to User Bucketing and for generated SDKs. * * API version: 1.0.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)

* DevCycle Bucketing API * * Documents the DevCycle Bucketing API which provides and API interface to User Bucketing and for generated SDKs. * * API version: 1.0.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)

Index

Constants

View Source
const CONFIG_RETRIES = 1
View Source
const NATIVE_SDK = false
View Source
const VERSION = "2.9.6"

Variables

View Source
var (
	// ContextOAuth2 takes a oauth2.TokenSource as authentication for the request.
	ContextOAuth2 = contextKey("token")

	// ContextBasicAuth takes BasicAuth as authentication for the request.
	ContextBasicAuth = contextKey("basic")

	// ContextAccessToken takes a string oauth2 access token as authentication for the request.
	ContextAccessToken = contextKey("accesstoken")

	// ContextAPIKey takes an APIKey as authentication for the request
	ContextAPIKey = contextKey("apikey")
)

Functions

func GeneratePlatformData added in v2.9.5

func GeneratePlatformData() *api.PlatformData

func SetLogger added in v2.3.0

func SetLogger(log Logger)

Types

type APIKey

type APIKey struct {
	Key    string
	Prefix string
}

APIKey provides API key based authentication to a request passed via context using ContextAPIKey

type APIResponse

type APIResponse struct {
	*http.Response `json:"-"`
	Message        string `json:"message,omitempty"`
	// Operation is the name of the swagger operation.
	Operation string `json:"operation,omitempty"`
	// RequestURL is the request URL. This value is always available, even if the
	// embedded *http.Response is nil.
	RequestURL string `json:"url,omitempty"`
	// Method is the HTTP method used for the request.  This value is always
	// available, even if the embedded *http.Response is nil.
	Method string `json:"method,omitempty"`
	// Payload holds the contents of the response body (which may be nil or empty).
	// This is provided here as the raw response.Body() reader will have already
	// been drained.
	Payload []byte `json:"-"`
}

func NewAPIResponse

func NewAPIResponse(r *http.Response) *APIResponse

func NewAPIResponseWithError

func NewAPIResponseWithError(errorMessage string) *APIResponse

type AdvancedOptions added in v2.7.0

type AdvancedOptions struct {
	// controls the maximum number of pre-allocated memory blocks used for WASM execution. This influences the maximum
	// string length that can be fit inside of preallocated memory
	// Can be set to -1 to disable pre-allocated memory blocks entirely.
	// This takes \sum_{k=5}^{n+5} 2^k memory usage
	MaxMemoryAllocationBuckets int
	MaxWasmWorkers             int
}

type BaseVariable added in v2.9.5

type BaseVariable = api.BaseVariable

type BasicAuth

type BasicAuth struct {
	UserName string `json:"userName,omitempty"`
	Password string `json:"password,omitempty"`
}

BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth

type BatchEventsBody

type BatchEventsBody = api.BatchEventsBody

type BucketedUserConfig

type BucketedUserConfig = api.BucketedUserConfig

type BucketingPool added in v2.9.0

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

func NewBucketingPool added in v2.9.0

func NewBucketingPool(ctx context.Context, wasmMain *WASMMain, sdkKey string, platformData *PlatformData, options *DVCOptions) (*BucketingPool, error)

func (*BucketingPool) Close added in v2.9.0

func (p *BucketingPool) Close()

func (*BucketingPool) ProcessAll added in v2.9.0

func (p *BucketingPool) ProcessAll(
	operationName string,
	process func(object *BucketingPoolObject) error,
) (err error)

ProcessAll will func the "process" handler function on every object in the pool. It will block until the operation has completed for every object, or there was an error. It naively grabs the longest idle object from the pool each time and checks if it has seen it before. If it has, it will immediately return it and try again.

func (*BucketingPool) SetClientCustomData added in v2.9.0

func (p *BucketingPool) SetClientCustomData(customData []byte) error

func (*BucketingPool) StoreConfig added in v2.9.4

func (p *BucketingPool) StoreConfig(config []byte) error

func (*BucketingPool) VariableForUser added in v2.9.0

func (p *BucketingPool) VariableForUser(paramsBuffer []byte) (*proto.SDKVariable_PB, error)

type BucketingPoolFactory added in v2.9.0

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

func MakeBucketingPoolFactory added in v2.9.0

func MakeBucketingPoolFactory(wasmMain *WASMMain, sdkKey string, platformData *PlatformData, options *DVCOptions, pool *BucketingPool) *BucketingPoolFactory

func (*BucketingPoolFactory) ActivateObject added in v2.9.0

func (f *BucketingPoolFactory) ActivateObject(ctx context.Context, object *pool.PooledObject) error

func (*BucketingPoolFactory) DestroyObject added in v2.9.0

func (f *BucketingPoolFactory) DestroyObject(ctx context.Context, object *pool.PooledObject) error

func (*BucketingPoolFactory) MakeObject added in v2.9.0

func (f *BucketingPoolFactory) MakeObject(ctx context.Context) (*pool.PooledObject, error)

func (*BucketingPoolFactory) PassivateObject added in v2.9.0

func (f *BucketingPoolFactory) PassivateObject(ctx context.Context, object *pool.PooledObject) error

func (*BucketingPoolFactory) ValidateObject added in v2.9.0

func (f *BucketingPoolFactory) ValidateObject(ctx context.Context, object *pool.PooledObject) bool

type BucketingPoolObject added in v2.9.0

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

func (*BucketingPoolObject) FlushEvents added in v2.9.0

func (o *BucketingPoolObject) FlushEvents() ([]FlushPayload, error)

func (*BucketingPoolObject) HandleFlushResults added in v2.9.0

func (o *BucketingPoolObject) HandleFlushResults(result *FlushResult)

func (*BucketingPoolObject) Initialize added in v2.9.0

func (o *BucketingPoolObject) Initialize(wasmMain *WASMMain, sdkKey string, platformData *PlatformData, options *DVCOptions) (err error)

func (*BucketingPoolObject) SetClientCustomData added in v2.9.0

func (o *BucketingPoolObject) SetClientCustomData(clientCustomData *[]byte) (err error)

func (*BucketingPoolObject) StoreConfig added in v2.9.0

func (o *BucketingPoolObject) StoreConfig(config *[]byte) (err error)

type ConfigReceiver added in v2.9.4

type ConfigReceiver interface {
	StoreConfig([]byte, string) error
}

type DVCClient

type DVCClient struct {
	DevCycleOptions *DVCOptions
	// contains filtered or unexported fields
}

DVCClient In most cases there should be only one, shared, DVCClient.

func NewDVCClient

func NewDVCClient(sdkKey string, options *DVCOptions) (*DVCClient, error)

NewDVCClient creates a new API client. optionally pass a custom http.Client to allow for advanced features such as caching.

func (*DVCClient) AllFeatures

func (c *DVCClient) AllFeatures(user DVCUser) (map[string]Feature, error)

DVCClientService Get all features by key for user data

  • @param body

@return map[string]Feature

func (*DVCClient) AllVariables

func (c *DVCClient) AllVariables(user DVCUser) (map[string]ReadOnlyVariable, error)

func (*DVCClient) ChangeBasePath

func (c *DVCClient) ChangeBasePath(path string)

Change base path to allow switching to mocks

func (*DVCClient) Close

func (c *DVCClient) Close() (err error)

Close the client and flush any pending events. Stop any ongoing tickers

func (*DVCClient) FlushEvents

func (c *DVCClient) FlushEvents() error

func (*DVCClient) SetClientCustomData added in v2.2.0

func (c *DVCClient) SetClientCustomData(customData map[string]interface{}) error

func (*DVCClient) SetOptions

func (c *DVCClient) SetOptions(dvcOptions DVCOptions)

func (*DVCClient) Track

func (c *DVCClient) Track(user DVCUser, event DVCEvent) (bool, error)

func (*DVCClient) Variable

func (c *DVCClient) Variable(userdata DVCUser, key string, defaultValue interface{}) (result Variable, err error)

Variable - Get variable by key for user data

  • @param body

  • @param key Variable key

    -@return Variable

type DVCEvent

type DVCEvent = api.DVCEvent

type DVCOptions

type DVCOptions struct {
	EnableEdgeDB                 bool          `json:"enableEdgeDb,omitempty"`
	EnableCloudBucketing         bool          `json:"enableCloudBucketing,omitempty"`
	EventFlushIntervalMS         time.Duration `json:"eventFlushIntervalMS,omitempty"`
	ConfigPollingIntervalMS      time.Duration `json:"configPollingIntervalMS,omitempty"`
	RequestTimeout               time.Duration `json:"requestTimeout,omitempty"`
	DisableAutomaticEventLogging bool          `json:"disableAutomaticEventLogging,omitempty"`
	DisableCustomEventLogging    bool          `json:"disableCustomEventLogging,omitempty"`
	MaxEventQueueSize            int           `json:"maxEventsPerFlush,omitempty"`
	FlushEventQueueSize          int           `json:"minEventsPerFlush,omitempty"`
	ConfigCDNURI                 string
	EventsAPIURI                 string
	OnInitializedChannel         chan bool
	BucketingAPIURI              string
	Logger                       util.Logger
	UseDebugWASM                 bool
	AdvancedOptions
}

func (*DVCOptions) CheckDefaults

func (o *DVCOptions) CheckDefaults()

type DVCPopulatedUser added in v2.9.5

type DVCPopulatedUser = api.DVCPopulatedUser

type DVCUser

type DVCUser = api.DVCUser

type DiscardLogger added in v2.3.0

type DiscardLogger = util.DiscardLogger

type EdgeDBSettings

type EdgeDBSettings = api.EdgeDBSettings

type Environment

type Environment = api.Environment

type EnvironmentConfigManager

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

func NewEnvironmentConfigManager added in v2.9.4

func NewEnvironmentConfigManager(
	sdkKey string,
	localBucketing ConfigReceiver,
	options *DVCOptions,
	cfg *HTTPConfiguration,
) (e *EnvironmentConfigManager)

func (*EnvironmentConfigManager) Close

func (e *EnvironmentConfigManager) Close()

func (*EnvironmentConfigManager) HasConfig

func (e *EnvironmentConfigManager) HasConfig() bool

func (*EnvironmentConfigManager) StartPolling added in v2.9.4

func (e *EnvironmentConfigManager) StartPolling(
	interval time.Duration,
)

type ErrorResponse

type ErrorResponse = api.ErrorResponse

type EventQueue

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

func (*EventQueue) Close

func (e *EventQueue) Close() (err error)

func (*EventQueue) FlushEvents

func (e *EventQueue) FlushEvents() (err error)

func (*EventQueue) Metrics added in v2.8.0

func (e *EventQueue) Metrics() (int32, int32)

func (*EventQueue) QueueAggregateEvent

func (e *EventQueue) QueueAggregateEvent(config BucketedUserConfig, event DVCEvent) error

func (*EventQueue) QueueEvent

func (e *EventQueue) QueueEvent(user DVCUser, event DVCEvent) error

type EventQueueOptions

type EventQueueOptions = api.EventQueueOptions

type EventQueuer added in v2.9.5

type EventQueuer interface {
	QueueEvent(user DVCUser, event DVCEvent) error
	QueueAggregateEvent(config BucketedUserConfig, event DVCEvent) error
	FlushEvents() (err error)
	Metrics() (int32, int32)
	Close() (err error)
}

type Feature

type Feature = api.Feature

type FeatureVariation

type FeatureVariation = api.FeatureVariation

type FlushPayload

type FlushPayload = api.FlushPayload

type FlushResult added in v2.8.0

type FlushResult struct {
	SuccessPayloads          []string
	FailurePayloads          []string
	FailureWithRetryPayloads []string
}

type GenericError

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

GenericError Provides access to the body, error and model on returned errors.

func (GenericError) Body

func (e GenericError) Body() []byte

Body returns the raw bytes of the response

func (GenericError) Error

func (e GenericError) Error() string

Error returns non-empty string if there was an error.

func (GenericError) Model

func (e GenericError) Model() interface{}

Model returns the unpacked model of the error

type HTTPConfiguration

type HTTPConfiguration struct {
	BasePath          string            `json:"basePath,omitempty"`
	ConfigCDNBasePath string            `json:"configCDNBasePath,omitempty"`
	EventsAPIBasePath string            `json:"eventsAPIBasePath,omitempty"`
	Host              string            `json:"host,omitempty"`
	Scheme            string            `json:"scheme,omitempty"`
	DefaultHeader     map[string]string `json:"defaultHeader,omitempty"`
	UserAgent         string            `json:"userAgent,omitempty"`
	HTTPClient        *http.Client
}

func NewConfiguration

func NewConfiguration(options *DVCOptions) *HTTPConfiguration

func (*HTTPConfiguration) AddDefaultHeader

func (c *HTTPConfiguration) AddDefaultHeader(key string, value string)

type LocalBucketing added in v2.9.5

type LocalBucketing interface {
	ConfigReceiver
	GenerateBucketedConfigForUser(user DVCUser) (ret *BucketedUserConfig, err error)
	SetClientCustomData(map[string]interface{}) error
	Variable(user DVCUser, key string, variableType string) (variable Variable, err error)
	Close()
}

type Logger added in v2.3.0

type Logger = util.Logger

type OptInColors

type OptInColors = api.OptInColors

type OptInSettings

type OptInSettings = api.OptInSettings

type PlatformData

type PlatformData = api.PlatformData

type Project

type Project = api.Project

type ProjectSettings

type ProjectSettings = api.ProjectSettings

type ReadOnlyVariable

type ReadOnlyVariable = api.ReadOnlyVariable

type SDKEvent

type SDKEvent struct {
	Success             bool   `json:"success"`
	Message             string `json:"message"`
	Error               error  `json:"error"`
	FirstInitialization bool   `json:"firstInitialization"`
}

type UserDataAndEventsBody

type UserDataAndEventsBody = api.UserDataAndEventsBody

type UserEventsBatchRecord

type UserEventsBatchRecord = api.UserEventsBatchRecord

type UserFeatureData

type UserFeatureData = api.UserFeatureData

type Variable

type Variable = api.Variable

type VariableTypeCode added in v2.6.0

type VariableTypeCode int32

type VariableTypeCodes added in v2.6.0

type VariableTypeCodes struct {
	Boolean VariableTypeCode
	Number  VariableTypeCode
	String  VariableTypeCode
	JSON    VariableTypeCode
}

type WASMLocalBucketing added in v2.9.5

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

func NewWASMLocalBucketing added in v2.9.5

func NewWASMLocalBucketing(sdkKey string, platformData *PlatformData, options *DVCOptions) (*WASMLocalBucketing, error)

func (*WASMLocalBucketing) Close added in v2.9.5

func (lb *WASMLocalBucketing) Close()

func (*WASMLocalBucketing) GenerateBucketedConfigForUser added in v2.9.5

func (lb *WASMLocalBucketing) GenerateBucketedConfigForUser(user DVCUser) (ret *BucketedUserConfig, err error)

func (*WASMLocalBucketing) SetClientCustomData added in v2.9.5

func (lb *WASMLocalBucketing) SetClientCustomData(customData map[string]interface{}) error

func (*WASMLocalBucketing) StoreConfig added in v2.9.5

func (lb *WASMLocalBucketing) StoreConfig(config []byte, eTag string) error

func (*WASMLocalBucketing) Variable added in v2.9.5

func (lb *WASMLocalBucketing) Variable(user DVCUser, key string, variableType string) (variable Variable, err error)

type WASMLocalBucketingClient added in v2.9.5

type WASMLocalBucketingClient struct {
	VariableTypeCodes VariableTypeCodes
	// contains filtered or unexported fields
}

func (*WASMLocalBucketingClient) GenerateBucketedConfigForUser added in v2.9.5

func (d *WASMLocalBucketingClient) GenerateBucketedConfigForUser(user DVCUser) (ret *BucketedUserConfig, err error)

func (*WASMLocalBucketingClient) HandleFlushResults added in v2.9.5

func (d *WASMLocalBucketingClient) HandleFlushResults(result *FlushResult)

func (*WASMLocalBucketingClient) Initialize added in v2.9.5

func (d *WASMLocalBucketingClient) Initialize(wasmMain *WASMMain, sdkKey string, platformData *PlatformData, options *DVCOptions) (err error)

func (*WASMLocalBucketingClient) OnPayloadFailure added in v2.9.5

func (d *WASMLocalBucketingClient) OnPayloadFailure(payloadId string, retryable bool) (err error)

func (*WASMLocalBucketingClient) OnPayloadSuccess added in v2.9.5

func (d *WASMLocalBucketingClient) OnPayloadSuccess(payloadId string) (err error)

func (*WASMLocalBucketingClient) SetClientCustomData added in v2.9.5

func (d *WASMLocalBucketingClient) SetClientCustomData(customData []byte) error

func (*WASMLocalBucketingClient) SetPlatformDataJSON added in v2.9.5

func (d *WASMLocalBucketingClient) SetPlatformDataJSON(platformData []byte) error

func (*WASMLocalBucketingClient) StoreConfig added in v2.9.5

func (d *WASMLocalBucketingClient) StoreConfig(config []byte) error

func (*WASMLocalBucketingClient) VariableForUser_PB added in v2.9.5

func (d *WASMLocalBucketingClient) VariableForUser_PB(serializedParams []byte) (*proto.SDKVariable_PB, error)

* This is a helper function to call the variableForUserPB function in the WASM module. * It takes a serialized protobuf message as input and returns a serialized protobuf message as output.

func (*WASMLocalBucketingClient) VariableTypeCodeFromType added in v2.9.5

func (c *WASMLocalBucketingClient) VariableTypeCodeFromType(varType string) (varTypeCode VariableTypeCode, err error)

type WASMMain added in v2.7.0

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

func (*WASMMain) Initialize added in v2.7.0

func (d *WASMMain) Initialize(options *DVCOptions) (err error)

Directories

Path Synopsis
* DevCycle Bucketing API * * Documents the DevCycle Bucketing API which provides and API interface to User Bucketing and for generated SDKs.
* DevCycle Bucketing API * * Documents the DevCycle Bucketing API which provides and API interface to User Bucketing and for generated SDKs.
example
cloud command
local command

Jump to

Keyboard shortcuts

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