Setting the flag default values

This section describes flag default values and how to set them.

What are default values?

A flag default value is the value of the flag that is created when defining flags in the code. Default values are mandatory and flags cannot be created without them. They will be served when there is no configuration available (for any reason) or no other value overrides it.

Setting flag default value

A boolean flag is false by default. To override the value, pass the desired value to the flag.

A string flag has an explicit configuration for its default value.  In most languages, the first value would be the default value followed by an array of potential values.

With SDK version 5.0 or later use Rox.RoxString for String feature flags; examples are below.

In the example below, the title color can be any one of - White, Blue, Green and Yellow. By default, it will be White.

React NativeJavaScriptNode.jsJavaScript SSR.NETPythonGo
const flags = {
  titleColors: new Rox.RoxString('White', ['White', 'Blue', 'Green', 'Yellow']),
};
const flags = {
  titleColors: new Rox.RoxString('White', ['White', 'Blue', 'Green', 'Yellow']),
};
const flags = {
  titleColors: new Rox.RoxString('White', ['White', 'Blue', 'Green', 'Yellow']),
};
import {RoxString} from 'rox-ssr';

const flags = {
  titleColors: new RoxString('White', ['White', 'Blue', 'Green', 'Yellow']),
};
using Io.Rollout.Rox.Server.Flags;

public class Container : IRoxContainer
{
  public RoxString TitleColorsVariant = new RoxString("White", new String[] {"White", "Blue", "Green", "Yellow"});
}
from rox.core.entities.rox_string import RoxString

class MyContainer:
     def __init__(self):
        self.title_colors = RoxString('White', ['White', 'Blue', 'Green'])
import "github.com/rollout/rox-go/server"

type Flags struct {
        TitleColors server.RoxString
}

var flags = & Flags {
        TitleColors: server.NewRoxString("White", [] string {"White", "Blue", "Green", "Yellow"}),
}

With SDK version 4.x see examples below:

SwiftObjective-CAndroidReact NativeJavaScriptNode.jsJavaScript SSRJVM.NETPythonGoPHPRubyCC++
import Foundation
import ROX
public class Flags: RoxContainer{

  public let videoChat = RoxFlag(withDefault: true);
  public let titleColors = ROXVariant(withDefault: "White", options: ["White", "Blue", "Green", "Yellow"]);
}
#import "Flags.h"

@implementation Flags

- (instancetype)init {
  self = [super init];
  if (self) {
    self.videoChat = [[ROXFlag alloc] initWithDefaultValue:YES];
    self.titleColors = [[ROXVariant alloc] initWithDefault:"White" options:@[@"Blue", @"Green", @"Yellow"]];
  }

  return self;
}

@end
public class Flags implements RoxContainer {
  public final RoxFlag videoChat = new RoxFlag(true);
  public final RoxString titleColors = new RoxString("White", new String[] { "White", "Blue", "Green", "Yellow" });
  public final RoxInt intFlag = new RoxInt(2, new int[] { 1, 2, 3 });
  public final RoxDouble doubleFlag = new RoxDouble(2.2, new double[] { 1.1, 2.2, 3.3 });
}
const flags = {
  videoChat: new Rox.Flag(true),
  titleColors: new Rox.Variant('White', ['White', 'Blue', 'Green', 'Yellow']),
};
const flags = {
  videoChat: new Rox.Flag(true),
  titleColors: new Rox.Variant('White', ['White', 'Blue', 'Green', 'Yellow']),
};
const flags = {
  videoChat: new Rox.Flag(true),
  titleColors: new Rox.Variant('White', ['White', 'Blue', 'Green', 'Yellow']),
};
import {Rox} from 'rox-ssr';

const flags = {
  videoChat: new Flag(true),
  titleColors: new Rox.Variant('White', ['White', 'Blue', 'Green', 'Yellow']),
};
public class Flags implements RoxContainer {
  public final RoxFlag videoChat = new RoxFlag(true);
  public final RoxString titleColors = new RoxString("White", new String[] { "White", "Blue", "Green", "Yellow" });
  public final RoxInt intFlag = new RoxInt(2, new int[] { 1, 2, 3 });
  public final RoxDouble doubleFlag = new RoxDouble(2.2, new double[] { 1.1, 2.2, 3.3 });
}
public class Flags : IRoxContainer
{
  public RoxFlag videoChat = new RoxFlag(true);
  String[] TitleColorsOptions = new String[] {"White", "Blue", "Green", "Yellow"};
  RoxVariant TitleColorsVariant = new RoxVariant("White", TitleColorsOptions);
}
from rox.server.flags.rox_flag import RoxFlag

class MyContainer:
     def __init__(self):
        self.video_chat = RoxFlag(True)
        self.title_colors = RoxVariant('White', ['White', 'Blue', 'Green', 'Yellow'])
import (
        "github.com/rollout/rox-go/server"
)

type Container struct {
  VideoChat server.RoxFlag
  titleColors server.RoxVariant
}

var container = &Container {
  VideoChat: server.NewRoxFlag(true),
  titleColors: server.NewRoxVariant("White", []string{"White", "Blue", "Green", "Yellow"})}
}
class Container
{
    public $video_chat;
    public $titleColors;

    public function __construct()
    {
        $this->video_chat = new RoxFlag(true);
        $this->titleColors = new RoxVariant("White", ["White", "Blue", "Green", "Yellow"]);
    }
}
require 'rox/server/flags/rox_flag'

class Container
    attr_accessor :video_chat
    attr_accessor :title_colors

  def initialize
    @video_chat = Rox::Server::RoxFlag.new(true)
    @title_colors = Rox::Server::RoxVariant.new('White', ['White', 'Blue', 'Green', 'Yellow'])
  end
end
RoxVariant *videoChat = rox_add_flag("demo.video_chat", true);
RoxVariant *titleColor = rox_add_variant("titleColors", "White", ROX_LIST_COPY_STR("White", "Blue", "Green", "Yellow"));
    Rox::Flag *videoChat = Rox::Flag::Create("demo.video_chat", true);
    Rox::Variant *titleColor = Rox::Variant::Create("titleColors", "White", std::vector<std::string>{"White", "Blue", "Green", "Yellow"});