Kotlin Configuration
Builder Pattern
Section titled “Builder Pattern”val client = FlagsClient.builder() .auth(Auth( projectId = "your-project-id", agentId = "your-agent-id", environmentId = "your-environment-id" )) .baseUrl("https://custom-api.flags.gg") .maxRetries(5) .failureThreshold(10) .resetTimeout(Duration.ofMinutes(5)) .withMemoryCache() .build()Builder Methods
Section titled “Builder Methods”| Method | Default | Description |
|---|---|---|
auth(Auth) |
— | Required. Authentication credentials |
baseUrl(String) |
https://api.flags.gg |
Custom API endpoint |
maxRetries(Int) |
3 |
Max retry attempts |
failureThreshold(Int) |
3 |
Circuit breaker failure threshold |
resetTimeout(Duration) |
10 seconds |
Circuit breaker reset timeout |
withMemoryCache() |
Memory | Use in-memory cache |
withSQLiteCache(String) |
flags_cache.db |
Use a SQLite cache, so the last values survive a restart |
httpClient(HttpClient) |
— | Custom Ktor HTTP client |
targetingKey(String?) |
— | Stable user id for percentage rollouts. Without one, partial rollouts stay off |
context(Map<String, String>) / context(Map<String, List<String>>) |
— | User attributes for targeting rules |
Rollouts and Targeting Rules
Section titled “Rollouts and Targeting Rules”On Android, use your signed-in user’s id or a per-install id:
val prefs = context.getSharedPreferences("flags", Context.MODE_PRIVATE)val installId = prefs.getString("install_id", null) ?: UUID.randomUUID().toString().also { prefs.edit().putString("install_id", it).apply() }
val client = FlagsClient.builder() .auth(auth) .targetingKey(user?.id ?: installId) .context(mapOf("email" to listOf(user.email), "plan" to listOf(user.plan), "groups" to user.groups)) .build()
// later, e.g. after login or an upgrade; re-fetches flagsclient.setTargetingKey(user.id)client.setContext(mapOf("plan" to "pro"))isEnabled already accounts for both. See Rollouts & Targeting Rules.
Go-Style Options
Section titled “Go-Style Options”val client = FlagsClient.NewClient( WithAuth(auth), WithBaseURL("https://custom-api.flags.gg"), WithMaxRetries(5), WithMemory(), WithSQLite("custom.db"), WithHttpClient(customClient),)API Methods
Section titled “API Methods”Builder-style API
Section titled “Builder-style API”| Method | Returns | Description |
|---|---|---|
isEnabled(String) |
Boolean |
Check if a flag is enabled |
flag(String) |
Flag |
Get a flag object |
getAllFlags() |
List<FeatureFlag> |
Get all flags |
close() |
Unit |
Close the client and release resources |
Go-style API
Section titled “Go-style API”| Method | Returns | Description |
|---|---|---|
Is(String) |
FlagResult |
Get a flag result |
FlagResult.Enabled() |
Boolean |
Check if enabled |
Cleanup
Section titled “Cleanup”Always close the client when done to release HTTP connections:
client.close()