Feature flags are conditional statements around a coded functionality in an application. Create a Boolean, number, and/or string type flag in your application source code using the static API.
Create a container class and define feature flags
All flags are defined inside the required container class, and each flag name is derived from the flag variable name.
In each of the following code examples, a Boolean flag, a number flag, and a string flag are defined.
#import <rox/client.h> RoxStringBase *videoChat = rox_add_flag_with_freeze("demo.video_chat", false, RoxFreezeUntilLaunch); RoxStringBase* titleSize = rox_add_int_with_freeze_and_options("titleSize", 12, ROX_INT_LIST(14, 18, 24), RoxFreezeUntilLaunch); RoxStringBase* specialNumber = rox_add_double_with_freeze_and_options("specialNumber", 3.14, ROX_DBL_LIST(2.71, 0.577), RoxFreezeUntilLaunch); RoxStringBase* titleColors = rox_add_string_with_freeze_and_options("demo.titleColors", "White", ROX_LIST_COPY_STR("White", "Blue", "Green", "Yellow"), RoxFreezeUntilLaunch);
#import <rox/server.h> RoxStringBase *videoChat = rox_add_flag("demo.video_chat", false); RoxStringBase* titleSize = rox_add_int_with_options("titleSize", 12, ROX_INT_LIST(14, 18, 24)); RoxStringBase* specialNumber = rox_add_double_with_options("specialNumber", 3.14, ROX_DBL_LIST(2.71, 0.577)); RoxStringBase* titleColors = rox_add_string_with_options("demo.titleColors", "White", ROX_LIST_COPY_STR( "White", "Blue", "Green", "Yellow" ));
#import <roxx/client.h> using namespace Rox::Client; auto videoChat = Rox::Client::Flag::Create("demo.video_chat", false, RoxFreezeUntilLaunch); auto titleSize = Int::Create("titleSize", 12, {14, 18, 24}, RoxFreezeUntilLaunch); auto specialNumber = Double::Create("specialNumber", 3.14, {2.71, 0.577}, RoxFreezeUntilLaunch); auto titleColors = String::Create("demo.titleColors", "White", {"White", "Blue", "Green", "Yellow"}, RoxFreezeNone);
#import <roxx/server.h> using namespace Rox; auto videoChat = Rox::Flag::Create("demo.video_chat", false); auto titleSize = Int::Create("titleSize", 12, {14, 18, 24}); auto specialNumber = Double::Create("specialNumber", 3.14, {2.71, 0.577}); auto titleColors = String::Create("demo.titleColors", "White", {"White", "Blue", "Green", "Yellow"});
package main import ( "github.com/rollout/rox-go/v5/server" ) type myContainer struct { videoChat server.RoxFlag titleSize server.RoxInt specialNumber server.RoxDouble titleColor server.RoxString } var myFlags = & myContainer { // Define a Boolean flag inside the container videoChat: server.NewRoxFlag(false), // Define number flags inside the container titleSize: sever.NewRoxInt(12, [12, 14, 18, 24]), specialNumber: server.NewRoxDouble(99.9, [10.5, 50.0, 99.9]), // Define a string flag inside the container titleColor: server.NewRoxString("White", [] string {"White", "Blue", "Green", "Yellow"}) }
import io.rollout.configuration.RoxContainer; import io.rollout.flags.RoxDouble; import io.rollout.flags.RoxInt; import io.rollout.flags.RoxString; public static class Flags implements RoxContainer { // Define a Boolean flag inside the container public RoxFlag videoChat = new RoxFlag(); // Define number flags inside the container public final RoxInt titleSize = new RoxInt(12, new int[]{ 14, 18, 24 }); public final RoxDouble specialNumber = new RoxDouble(3.14, new double[]{ 2.71, 0.577 }); // Define a string flag inside the container public final RoxString titleColor = new RoxString("White", new String[]{ "White", "Blue", "Green", "Yellow" }); }
const flags = { // Define a Boolean flag inside the container videoChat: new Rox.Flag(), // Define a number flag inside the container titleSize: new Rox.RoxNumber(12, [12, 14, 18, 24]), // Define a string flag inside the container titleColor: new Rox.RoxString('White', ['White', 'Blue', 'Green', 'Yellow']) };
import {Flag} from 'rox-ssr'; const flags = { // Define a Boolean flag inside the container videoChat: new Rox.Flag(), // Define a number flag inside the container titleSize: new Rox.RoxNumber(12, [12, 14, 18, 24]), // Define a string flag inside the container titleColor: new Rox.RoxString('White', ['White', 'Blue', 'Green', 'Yellow']) };
using Io.Rollout.Rox.Server.Flags; public class Container : IRoxContainer { // Define a Boolean flag inside the container public RoxFlag videoChat = new RoxFlag(); // Define number flags inside the container public RoxInt titleSize = new RoxInt(12, new List<int>() { 14, 18, 24 }); public RoxDouble specialNumber = new RoxDouble(3.14, new List<int>() { 2.71, 0.577 }); // Define a string flag inside the container public RoxString TitleColorsVariant = new RoxString("White", new String[] {"White", "Blue", "Green", "Yellow"}); }
const flags = { // Define a Boolean flag inside the container videoChat: new Rox.Flag(), // Define a number flag inside the container titleSize: new Rox.RoxNumber(12, [12, 14, 18, 24]), // Define a string flag inside the container titleColor: new Rox.RoxString('White', ['White', 'Blue', 'Green', 'Yellow']) };
#import <ROXCore/ROXCore.h> @interface Flags : ROXBaseContainer @property (nonatomic) ROXFlag* videoChat; @property (nonatomic) ROXInt* titleSize; @property (nonatomic) ROXDouble* specialNumber; @property (nonatomic) ROXString* titleColors; @end #import "Flags.h" @implementation Flags - (instancetype)init { self = [super init]; if (self) { self.videoChat = [[ROXFlag alloc] init]; self.titleColors = [[ROXString alloc] initWithDefault:@"White" variations:@[@"Blue", @"Green", @"Yellow"]]; self.titleSize = [[ROXInt alloc] initWithDefault:12 variations:@[14, 18, 24]]; self.specialNumber = [[ROXDouble alloc] initWithDefault:3.14 variations:@[2.71, 0.577]]; } return self; } @end
use Rox\Server\Rox; use Rox\Server\Flags\RoxFlag; use Rox\Server\Flags\RoxDouble; use Rox\Server\Flags\RoxInt; use Rox\Server\Flags\RoxString; require __DIR__ . '/vendor/autoload.php'; class Container { public $videoChat; public $titleSize; public $specialNumber; public $titleColors; public function __construct() { $this->videoChat = new RoxFlag(false); $this->titleSize = new RoxInt(12, [14, 18, 24]); $this->specialNumber = new RoxDouble(3.14, [2.71, 0.577]); $this->titleColors = new RoxString("White", ["Blue", "Green", "Yellow"]); } }
from rox.server.flags.rox_flag import RoxFlag # Create a container class class MyContainer: def __init__(self): # Define a Boolean flag inside the container self.video_chat = RoxFlag() # Define a number flag inside the container self.title_size = RoxNumber(12, [12, 14, 18, 24]) # Define a string flag inside the container self.title_color = RoxString('White', ['White', 'Blue', 'Green', 'Yellow'])
const flags = { // Define a Boolean flag inside the container videoChat: new Rox.Flag(), // Define a number flag inside the container titleSize: new Rox.RoxNumber(12, [12, 14, 18, 24]), // Define a string flag inside the container titleColor: new Rox.RoxString('White', ['White', 'Blue', 'Green', 'Yellow']) };
require 'rox/server/rox_server' require 'rox/server/flags/rox_int' require 'rox/server/flags/rox_double' require 'rox/server/flags/rox_string' class MyContainer: attr_reader :video_chat, :title_size, :special_number, :title_colors def initialize @video_chat = Rox::Server::RoxFlag.new @title_size = Rox::Server::RoxInt.new(12, [14, 18, 24]) @special_number = Rox::Server::RoxDouble.new(3.14, [2.71, 0.577]) @title_colors = Rox::Server::RoxString.new('White', ['White', 'Blue', 'Green', 'Yellow']) end end
import Foundation import ROX import ROXCore public class Flags: RoxContainer{ // Define a Boolean flag inside the container public let videoChat = RoxFlag(); // Define number flags inside the container public let titleSize = RoxInt(withDefault: 12, variations: [14, 18, 24]) public let specialNumber = RoxDouble(withDefault: 3.14, variations: [2.71, 0.577]) // Define a string flag inside the container public let titleColors = ROXVariant(withDefault: "White", options: ["White", "Blue", "Green", "Yellow"]) // for Enum-based string flag public let titleColorsEnum = RoxEnumVariant(Colors.White) } enum Colors : Int { case White case Blue case Green case Yellow }
Register the container class of feature flags and set up the SDK key
To use the container class, its instance must be registered to the platform SDK. The namespace parameter is a logical separation between containers, and is a criterion in filtering flags.
A namespace can only be registered once. |
In the following examples, a Rox SDK function is called to register the class instance, and then the environment key is set up.
rox := server.NewRox() rox.Register(myFlags) <-rox.Setup("<YOUR-SDK-KEY>")
Flags myFlags = new Flags(); Rox.register("<namespace>", myFlags); Rox.setup(<YOUR-SDK-KEY>);
Rox.register('<namespace>', flags); Rox.setup('<YOUR-SDK-KEY>');
Rox.register('<namespace>', flags); Rox.setup('<YOUR-SDK-KEY>');
Rox.Register("<namespace>", flags); await Rox.Setup(<YOUR-SDK-KEY>);
Rox.register('<namespace>', flags); await Rox.setup('<YOUR-SDK-KEY>');
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [ROX register:[[Flags alloc] init]]; [ROX setupWithKey:@<YOUR-SDK-KEY>]; return YES; }
use Rox\Server\Rox; use Rox\Server\Flags\RoxFlag; use Rox\Server\Flags\RoxString; class Container { public $videoChat; public $titleColors; public function __construct() { $this->videoChat = new RoxFlag(); $this->titleColors = new RoxString("White", ["White", "Blue", "Green", "Yellow"]); } } $container = new Container(); Rox::register(<namespace>, $container); Rox::setup(<YOUR-SDK-KEY>);
# Register the container class instance to the platform SDK from rox.server.rox_server import Rox my_flags = MyContainer() Rox.register(<namespace>, my_flags) Rox.setup(<YOUR-SDK-KEY>)
Rox.register('<namespace>', flags); await Rox.setup('<YOUR-SDK-KEY>');
require 'rox/server/rox_server' class Container end flags = Container.new Rox::Server::RoxServer.register(<namespace>, flags) Rox::Server::RoxServer.setup(<YOUR-SDK-KEY>).join
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { ROX.register("<namespace>", container: Flags()) ROX.setup(withKey: <YOUR-SDK-KEY>) return true }
Check the flag values
The following examples check the feature flag values.
The default flag value
The default flag value, which is the flag value when configuration is disabled, is the value specified in the code.
If no value for a Boolean flag is specified in your code, the default value is false
.
Number and string flags must have a default value defined for when configuration is disabled.
Flag freeze is available on client-side SDKs by default.
The default is set to |