Rollout.io - Documentation

type Rox

import "github.com/rollout/rox-go/server"
server.NewRox()

The Rox instance provides your application its primary interface with feature flags in the Rollout system. This is the central repository for your application's flags, it handles communications with the server to obtain the latest values, experiment settings, and configurations. It provides a mechanism through which you can use the feature flags to control your application's behavior. It works with a RoxContainer-derived object, which holds your application's feature flags. The values contained in the provided container will be marked as feature flags and will appear in your application's Rollout.io dashboard once the application is run.

This type also allows you to manage custom properties. These can be static settings of type string, boolean, integer, or double, or you can use a generator type to provide a custom property that is dependent upon code state.

You can also use a RoxOptions object to configure some aspects of this type. You can set the verbosity level, custom platform, global freeze level, impression handler, fetch handler,

Setup

Setup(apiKey string, roxOptions model.RoxOptions) <-chan struct{}

Configures the Rox object to work with the provided application.

Parameters

Parameter
Modifier and Type
Description

apiKey

string

The environment key provided by Rollout dashbaord

options

RoxOptions

A RoxOptions instance with the desired configuration for this application

Returns

Channel that indicates when the SDK has received the configuration from Rollout servers

Register

`Register(namespace string, roxContainer interface{})

Registers a feature flag container with the Rox client. The public member variables of this container will become a flag in your Rollout dashboard and will be named with the object name

Parameters

Parameter
Modifier and Type
Description

namespace

string

The prefix namespace for all flags in this container

container

interface

An object that contains your application's feature flags

Example:
Assuming we have the following container

 
type Container struct {
  IncludeFacebook server.RoxFlag
  IncludeGithub server.RoxFlag
  
}

and we register the container with the following code:

var container = &Container {
  IncludeFacebook: server.NewRoxFlag(false),
  IncludeGithub: server.NewRoxFlag(false),
}
Rox.Register("Login", conf);
<-Rox.Setup(rolloutKey, nil);

The flag and configuration in the dashboard will have the names
Login.includeFacebook and Login.includeGithub.
This is very handy if you want to have groups of flags and configuration.

If you don't need a namespace, you can set the namespace to an empty string.

SetCustomComputedBooleanProperty

SetCustomComputedBooleanProperty(name string, value properties.CustomBooleanPropertyGenerator)

Sets a custom Computed Boolean property on the Rox client. This is a computable boolean, with an object that generates the value for the property.

Parameters

Parameter
Modifier and Type
Description

name

string

The name of the property to create

generator

properties.CustomBooleanPropertyGenerator

An instance of the Boolean property's generator type

SetCustomComputedFloatProperty

SetCustomComputedFloatProperty(name string, value properties.CustomFloatPropertyGenerator)

Sets a custom Computed Float property on the Rox client. This is a computable float, with an object that generates the value for the property.

Parameters

Parameter
Modifier and Type
Description

name

string

The name of the property to create

generator

properties.CustomFloatPropertyGenerator

An instance of the Float property's generator type

SetCustomComputedIntegerProperty

SetCustomComputedIntegerProperty(name string, value properties.CustomIntegerPropertyGenerator)

Sets a custom Computed Integer property on the Rox client. This is a computable integer, with an object that generates the value for the property.

Parameters

Parameter
Modifier and Type
Description

name

string

The name of the property to create

generator

properties.CustomIntegerPropertyGenerator

An instance of the Integer property's generator type

SetCustomComputedSemverProperty

SetCustomComputedSemverProperty(name string, value properties.CustomSemverPropertyGenerator)

Sets a custom Computed Semantic-versioned string property on the Rox client. This is a computable semantically-versioned string, with an object that generates the value for the property.

Parameters

Parameter
Modifier and Type
Description

name

string

The name of the property to create

generator

properties.CustomSemverPropertyGenerator

An instance of the string property's generator type

SetCustomComputedStringProperty

SetCustomComputedStringProperty(name string, value properties.CustomStringPropertyGenerator)

Sets a custom computed string property on the Rox client. This is a computable string, with an object that generates the value for the property.

Parameters

Parameter
Modifier and Type
Description

name

string

The name of the property to create

generator

properties.CustomStringPropertyGenerator

An instance of the string property's generator type

SetCustomBooleanProperty

SetCustomBooleanProperty(name string, value bool)

Sets a custom property representing a bool value

Parameters

Parameter
Modifier and Type
Description

name

string

The name of the custom property

value

bool

The value for the custom property

SetCustomFloatProperty

SetCustomFloatProperty(name string, value float64)
Sets a custom property that can store a specified float value.

Parameters

Parameter
Modifier and Type
Description

name

string

The property name

value

float64

The value of the property

SetCustomIntegerProperty

SetCustomIntegerProperty(name string, value int)

Sets a custom property that can store a specified integer value.

Parameters

Parameter
Modifier and Type
Description

name

string

The property name

value

int

The value of the property

SetCustomSemverProperty

SetCustomSemverProperty(name string, value string)

Sets a custom property that uses a Semantic Version as its value. See semver.org for more information on Semantic Versioning

Parameters

Parameter
Modifier and Type
Description

name

string

The name of the property to create

value

string

The property value, formatted using the rules defined at semver.org

SetCustomStringProperty

SetCustomStringProperty(name string, value string)

Sets a custom string property for the Rox client, which is a string property you can fetch by name
Parameters

Parameter
Modifier and Type
Description

name

string

The name of the property to create

value

string

The property's value

SetContext

SetContext(ctx context.Context)

Set a global context, this context will be available to all flags evaluations

Fetch

Fetch() <-chan struct{}

Create a network request for the latest configuration

type RoxOptions

import "github.com/rollout/rox-go/server"
server.NewRoxOptions()

RoxOptions covers configuration options for the Rox client. This includes settings like the verbosity of the logging. Instances of this type should be created using server.NewRoxOptions

Example
Here is an example of setting up a new RoxOptions object. This options object sets the version, logger, providing an impression handler, fetch handler, and more.

 options := server.NewRoxOptions(server.RoxOptionsBuilder{
    Logger:     &logger{},
    ConfigurationFetchedHandler: func(e *model.ConfigurationFetchedArgs) {
      if e != nil && e.FetcherStatus == model.FetcherStatusAppliedFromNetwork {
        TestVarsConfigurationFetchedCount++
      }
    },
    ImpressionHandler: func(e model.ImpressionArgs) {
      if e.ReportingValue != nil {
        if e.ReportingValue.Name == "FlagForImpression" {
          TestVarsIsImpressionRaised = true
        }
      }
      TestVarsImpressionReturnedArgs = &e
    },
  })
  rox = server.NewRox()
 

  <-rox.Setup("<Rollout_Key>", options)

type RoxOptions.RoxOptionsBuilder

server.RoxOptionsBuilder{...}

This Builder type is used to create a new RoxOptions instance.

Version

Set the version of the service running Rollout SDK

FetchInterval

Set the polling interval for fetching configuration from Rollout storage service

Logger

Set the Logger to be used for logging

type logger struct {
}

func (*logger) Debug(message string, err interface{}) {
  fmt.Println("Debug:", message)
}

func (*logger) Warn(message string, err interface{}) {
	fmt.Println("Warn", message)
}

func (*logger) Error(message string, err interface{}) {
	fmt.Println("Error", message)
}

ConfigurationFetchedHandler

Set the configuration event handler, to add actions after configurations were fetched

ImpressionHandler

Set the impression event handler, to add actions after an impression

RoxyURL

A roxy url (see Microservices Automated Testing and Local development )

RoxContainer

The RoxContainer instance for your application will contain all of the feature flags for the features in your application. These feature flags are converted into Rollout flags when the container is registered with Rox using Register(namespace string, container interface{}). Feature flag names will be derived from the provided flag variable names

Example

Below is a quick example of how to use this container class:

 
var container = &Container {
  IncludeFacebook: server.NewRoxFlag(false),
  IncludeGithub: server.NewRoxFlag(false),
}
Rox.Register("login", conf);
<-Rox.Setup(rolloutKey, nil);


type RoxFlag

import "github.com/rollout/rox-go/server"
server.NewRoxFlag

RoxFlag is a boolean feature flag. It can be either true or false

IsEnabled

IsEnabled(ctx context.Context) bool

Returns true if the flag is enabled based on given context

import "github.com/rollout/rox-go/core/context"

ctx := context.NewContext(map[string]interface{}{"email": "some@email.com"})
flagImpressionValue := container.IncludeFacebook.IsEnabled(ctx)

Name

Name() string

The name of the Flag

Class RoxVariant

import "github.com/rollout/rox-go/server"
func NewRoxVariant(defaultValue string, options []string) RoxVariant

RoxVariant is a feature flag object that can have values more complex than a simple boolean true or false. RoxVariant accepts a list of possible values for the feature flag and a default value. This list of values will be used when selecting new values for the feature and will be available for override via the Rollout's dashboard.

Example

var container = &Container {
		Variant: server.NewRoxVariant("red", []string{"red", "blue", "green"}) 
}

ctx := context.NewContext(map[string]interface{}{"gender": "female})
container.VariantWithContext.GetValue(ctx)

GetValue

GetValue(context context.Context) string

Returns the variant's value considering the context given

Name

Name() string

The name of the Variant

Context interface

import "github.com/rollout/rox-go/core/context"
context.NewContext

The context object is used to pass data to the Flag when checking if the current flag is enabled or disabled, this object is used by the registered CustomProperties to evaluate the experiment expression and return the flag value

You can create a context using the NewContext function by sending a map as the argument

Example

someContext := context.NewContext(map[string]interface{}{"user": user})

Get

Get(key string) interface{}

This get function is used to retrieve data from the context

Example
In this example can see how the SetComputedStringProperty is using the context to get the username

 rox.SetCustomComputedBooleanProperty("hasItemsInShoppingCart", func(ctx context.Context) bool {
	value, _ := ctx.Get("shoppingCart").(*ShoppingCart)
	return value.IsEmpty() })

Go API


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.