Assignments
Assignments are the mechanism through which a given Subject is assigned to a variation for a feature flag or experiment.
The Eppo SDK supports the following assignment types:
- String
- Boolean
- JSON
- Integer
- Float
Assignment Types
String Assignments
String assignments return a string value that is set as the variation. String flags are the most common type of flags and are useful for both A/B/n tests and advanced targeting use cases.
import (
"github.com/eppo-exp/golang-sdk/v6/eppoclient"
)
subjectAttributes := map[string]interface{}{
"country": user.Country,
"age": 30,
}
variation, err := client.GetStringAssignment(
"flag-key-123",
user.ID,
subjectAttributes,
"control",
)
if err != nil {
log.Printf("Error getting assignment: %v", err)
return
}
switch variation {
case "version-a":
handleVersionA()
case "version-b":
handleVersionB()
default:
handleControl()
}
Boolean Assignments
Boolean flags support simple on/off toggles. They're useful for simple, binary feature switches like blue/green deployments or enabling/disabling a new feature.
enabled, err := client.GetBooleanAssignment(
"new-feature",
user.ID,
subjectAttributes,
false, // default value
)
if err != nil {
log.Printf("Error getting assignment: %v", err)
return
}
if enabled {
handleFeatureEnabled()
} else {
handleFeatureDisabled()
}
JSON Assignments
JSON flags work best for advanced configuration use cases. The JSON flag can include structured information such as:
- Marketing copy for a promotional campaign
- Configuration parameters for a feature
- UI customization settings
defaultCampaign := map[string]interface{}{
"hero": false,
"hero_image": "placeholder.png",
"hero_title": "Placeholder Hero Title",
"hero_description": "Placeholder Hero Description",
}
campaignConfig, err := client.GetJSONAssignment(
"campaign-config",
user.ID,
subjectAttributes,
defaultCampaign,
)
if err != nil {
log.Printf("Error getting assignment: %v", err)
return
}
// You can also get the raw JSON bytes
campaignBytes, err := client.GetJSONBytesAssignment(
"campaign-config",
user.ID,
subjectAttributes,
defaultCampaignBytes,
)