devcycle

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: MIT Imports: 28 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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"
package main
import "github.com/devcyclehq/go-server-sdk"

Getting Started

    environmentKey := os.Getenv("DVC_SERVER_KEY")
	user := devcycle.UserData{UserId: "test"}
	auth := context.WithValue(context.Background(), devcycle.ContextAPIKey, devcycle.APIKey{
		Key: environmentKey,
	})

	dvcOptions := devcycle.DVCOptions{
		EnableEdgeDB:                 false,
		DisableLocalBucketing:        false,
		EventsFlushInterval:          0,
		PollingInterval:              10 * time.Second,
		RequestTimeout:               10 * time.Second,
		DisableAutomaticEventLogging: false,
		DisableCustomEventLogging:    false,
	}

	lb, err := devcycle.InitializeLocalBucketing(environmentKey, &dvcOptions)
	if err != nil {
		log.Fatal(err)
	}
	client, _ := devcycle.NewDVCClient(environmentKey, &dvcOptions, lb)

Usage

To find usage documentation, visit our docs.

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)

* 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)

* 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)

* 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)

* 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 (
	EventType_VariableEvaluated    = "variableEvaluated"
	EventType_AggVariableEvaluated = "aggVariableEvaluated"
	EventType_VariableDefaulted    = "variableDefaulted"
	EventType_AggVariableDefaulted = "aggVariableDefaulted"
)
View Source
const VERSION = "1.2.0"

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 CacheExpires

func CacheExpires(r *http.Response) time.Time

CacheExpires helper function to determine remaining time before repeating a request.

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 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 added in v1.2.0

type BatchEventsBody struct {
	Records []UserEventsBatchRecord `json:"batch,omitempty"`
}

type BucketedUserConfig added in v1.2.0

type BucketedUserConfig struct {
	Project             Project             `json:"project"`
	Environment         Environment         `json:"environment"`
	Features            map[string]Feature  `json:"features"`
	FeatureVariationMap map[string]string   `json:"featureVariationMap"`
	Variables           map[string]Variable `json:"variables"`
	KnownVariableKeys   []float64           `json:"knownVariableKeys"`
	// contains filtered or unexported fields
}

type DVCClient

type DVCClient struct {

	// API Services
	DevCycleApi     *DVCClientService
	DevCycleOptions *DVCOptions
	// contains filtered or unexported fields
}

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

func NewDVCClient

func NewDVCClient(environmentKey string, options *DVCOptions, localBucketing *DevCycleLocalBucketing) (*DVCClient, error)

NewDVCClient creates a new API client. Requires a userAgent string describing your application. optionally a custom http.Client to allow for advanced features such as caching.

func (*DVCClient) ChangeBasePath

func (c *DVCClient) ChangeBasePath(path string)

Change base path to allow switching to mocks

func (*DVCClient) SetOptions added in v1.1.0

func (c *DVCClient) SetOptions(dvcOptions DVCOptions)

type DVCClientService

type DVCClientService service

func (*DVCClientService) AllFeatures

func (a *DVCClientService) AllFeatures(ctx context.Context, body UserData) (map[string]Feature, error)

DVCClientService Get all features by key for user data

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param body

@return map[string]Feature

func (*DVCClientService) AllVariables

func (a *DVCClientService) AllVariables(ctx context.Context, body UserData) (map[string]Variable, error)

func (*DVCClientService) FlushEvents added in v1.2.0

func (a *DVCClientService) FlushEvents() error

func (*DVCClientService) Track

func (a *DVCClientService) Track(ctx context.Context, user UserData, event DVCEvent) (bool, error)

func (*DVCClientService) Variable

func (a *DVCClientService) Variable(ctx context.Context, userdata UserData, key string, defaultValue interface{}) (Variable, error)

DVCClientService Get variable by key for user data

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param body
  • @param key Variable key

@return Variable

type DVCEvent added in v1.2.0

type DVCEvent struct {
	Type_       string                 `json:"type"`
	Target      string                 `json:"target,omitempty"`
	CustomType  string                 `json:"customType,omitempty"`
	UserId      string                 `json:"user_id,omitempty"`
	ClientDate  time.Time              `json:"clientDate,omitempty"`
	Value       float64                `json:"value,omitempty"`
	FeatureVars map[string]string      `json:"featureVars,omitempty"`
	MetaData    map[string]interface{} `json:"metaData,omitempty"`
}

type DVCOptions added in v1.1.0

type DVCOptions struct {
	EnableEdgeDB                 bool          `json:"enableEdgeDb,omitempty"`
	DisableLocalBucketing        bool          `json:"disableLocalBucketing,omitempty"`
	EventsFlushInterval          time.Duration `json:"eventsFlushInterval,omitempty"`
	PollingInterval              time.Duration `json:"pollingInterval,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"`
	ConfigCDNOverride            string
	EventsAPIOverride            string
}

func (*DVCOptions) CheckDefaults added in v1.2.0

func (o *DVCOptions) CheckDefaults()

type DevCycleLocalBucketing added in v1.2.0

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

func InitializeLocalBucketing added in v1.2.0

func InitializeLocalBucketing(environmentKey string, options *DVCOptions) (ret *DevCycleLocalBucketing, err error)

func (*DevCycleLocalBucketing) GenerateBucketedConfigForUser added in v1.2.0

func (d *DevCycleLocalBucketing) GenerateBucketedConfigForUser(user string) (ret BucketedUserConfig, err error)

func (*DevCycleLocalBucketing) Initialize added in v1.2.0

func (d *DevCycleLocalBucketing) Initialize(sdkToken string, options *DVCOptions) (err error)

func (*DevCycleLocalBucketing) SetPlatformData added in v1.2.0

func (d *DevCycleLocalBucketing) SetPlatformData(platformData string) error

func (*DevCycleLocalBucketing) SetSDKToken added in v1.2.0

func (d *DevCycleLocalBucketing) SetSDKToken(token string)

func (*DevCycleLocalBucketing) StoreConfig added in v1.2.0

func (d *DevCycleLocalBucketing) StoreConfig(token, config string) error

type EdgeDBSettings added in v1.2.0

type EdgeDBSettings struct {
	Enabled bool `json:"enabled"`
}

type Environment added in v1.2.0

type Environment struct {
	Id  string `json:"_id"`
	Key string `json:"key"`
}

type EnvironmentConfigManager added in v1.2.0

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

func (*EnvironmentConfigManager) Initialize added in v1.2.0

func (e *EnvironmentConfigManager) Initialize(environmentKey string, options *DVCOptions) (err error)

type ErrorResponse

type ErrorResponse struct {
	// Error message
	Message string `json:"message"`
	// Additional error information detailing the error reasoning
	Data interface{} `json:"data,omitempty"`
}

type EventQueue added in v1.2.0

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

func (*EventQueue) FlushEvents added in v1.2.0

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

func (*EventQueue) QueueAggregateEvent added in v1.2.0

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

func (*EventQueue) QueueEvent added in v1.2.0

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

type EventQueueOptions added in v1.2.0

type EventQueueOptions struct {
	FlushEventsInterval          time.Duration `json:"flushEventsMS"`
	DisableAutomaticEventLogging bool          `json:"disableAutomaticEventLogging"`
	DisableCustomEventLogging    bool          `json:"disableCustomEventLogging"`
}

type Feature

type Feature struct {
	// unique database id
	Id string `json:"_id"`
	// Unique key by Project, can be used in the SDK / API to reference by 'key' rather than _id.
	Key string `json:"key"`
	// Feature type
	Type_ string `json:"type"`
	// Bucketed feature variation
	Variation string `json:"_variation"`
	// Bucketed feature variation key
	VariationKey string `json:"variationKey"`
	// Bucketed feature variation name
	VariationName string `json:"variationName"`
	// Evaluation reasoning
	EvalReason string `json:"evalReason,omitempty"`
}

type FlushPayload added in v1.2.0

type FlushPayload struct {
	PayloadId  string                  `json:"payloadId,omitempty"`
	EventCount int                     `json:"eventCount,omitempty"`
	Records    []UserEventsBatchRecord `json:"records,omitempty"`
}

type GenericSwaggerError

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

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

func (GenericSwaggerError) Body

func (e GenericSwaggerError) Body() []byte

Body returns the raw bytes of the response

func (GenericSwaggerError) Error

func (e GenericSwaggerError) Error() string

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

func (GenericSwaggerError) Model

func (e GenericSwaggerError) Model() interface{}

Model returns the unpacked model of the error

type HTTPConfiguration added in v1.2.0

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 added in v1.2.0

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

type OptInColors added in v1.2.0

type OptInColors struct {
	Primary   string `json:"primary"`
	Secondary string `json:"secondary"`
}

type OptInSettings added in v1.2.0

type OptInSettings struct {
	Enabled     bool        `json:"enabled"`
	Title       string      `json:"title"`
	Description string      `json:"description"`
	ImageURL    string      `json:"imageURL"`
	Colors      OptInColors `json:"colors"`
}

type PlatformData added in v1.2.0

type PlatformData struct {
	SdkType         string `json:"sdkType"`
	SdkVersion      string `json:"sdkVersion"`
	PlatformVersion string `json:"platformVersion"`
	DeviceModel     string `json:"deviceModel"`
	Platform        string `json:"platform"`
	Hostname        string `json:"hostname"`
}

func (*PlatformData) Default added in v1.2.0

func (pd *PlatformData) Default(isLocal bool) *PlatformData

func (*PlatformData) FromUser added in v1.2.0

func (pd *PlatformData) FromUser(user UserData) PlatformData

type Project added in v1.2.0

type Project struct {
	Id               string          `json:"_id"`
	Key              string          `json:"key"`
	A0OrganizationId string          `json:"a0_organization"`
	Settings         ProjectSettings `json:"settings"`
}

type ProjectSettings added in v1.2.0

type ProjectSettings struct {
	EdgeDB EdgeDBSettings `json:"edgeDB"`
	OptIn  OptInSettings  `json:"optIn"`
}

type SDKEvent added in v1.2.0

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

type UserData

type UserData struct {
	// Unique id to identify the user
	UserId string `json:"user_id"`
	// User's email used to identify the user on the dashboard / target audiences
	Email string `json:"email,omitempty"`
	// User's name used to identify the user on the dashboard / target audiences
	Name string `json:"name,omitempty"`
	// User's language in ISO 639-1 format
	Language string `json:"language,omitempty"`
	// User's country in ISO 3166 alpha-2 format
	Country string `json:"country,omitempty"`
	// App Version of the running application
	AppVersion string `json:"appVersion,omitempty"`
	// App Build number of the running application
	AppBuild string `json:"appBuild,omitempty"`
	// User's custom data to target the user with, data will be logged to DevCycle for use in dashboard.
	CustomData map[string]interface{} `json:"customData,omitempty"`
	// User's custom data to target the user with, data will not be logged to DevCycle only used for feature bucketing.
	PrivateCustomData map[string]interface{} `json:"privateCustomData,omitempty"`
	// Date the user was created, Unix epoch timestamp format
	CreatedDate time.Time `json:"createdDate,omitempty"`
	// Date the user was created, Unix epoch timestamp format
	LastSeenDate time.Time `json:"lastSeenDate,omitempty"`
	// Platform the Client SDK is running on
	Platform string `json:"platform,omitempty"`
	// Version of the platform the Client SDK is running on
	PlatformVersion string `json:"platformVersion,omitempty"`
	// User's device model
	DeviceModel string `json:"deviceModel,omitempty"`
	// DevCycle SDK type
	SdkType string `json:"sdkType,omitempty"`
	// DevCycle SDK Version
	SdkVersion string `json:"sdkVersion,omitempty"`
}

type UserDataAndEventsBody

type UserDataAndEventsBody struct {
	Events []DVCEvent `json:"events,omitempty"`
	User   *UserData  `json:"user,omitempty"`
}

type UserEventsBatchRecord added in v1.2.0

type UserEventsBatchRecord struct {
	User   UserData   `json:"user"`
	Events []DVCEvent `json:"events"`
}

type UserFeatureData added in v1.2.0

type UserFeatureData struct {
	User        UserData `json:"user"`
	FeatureVars map[string]string
}

type Variable

type Variable struct {
	// unique database id
	Id string `json:"_id"`
	// Unique key by Project, can be used in the SDK / API to reference by 'key' rather than _id.
	Key string `json:"key"`
	// Variable type
	Type_ string `json:"type"`
	// Variable value can be a string, number, boolean, or JSON
	Value interface{} `json:"value"`
	// Identifies if variable was returned with the default value
	IsDefaulted bool `json:"isDefaulted,omitempty"`
}

Directories

Path Synopsis
example
cloud command
local command

Jump to

Keyboard shortcuts

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