Migrating from Legacy Go SDK to Go Core
Learn how to migrate from the legacy Go Server SDK to the new Go Core SDK with improved performance and new features
This guide covers migrating from the legacy Go Server SDK to the Go Core SDK. The Go Core SDK offers significant performance improvements and new features, built on a shared Rust core library.
Why migrate?
- Performance: Go Core achieves faster evaluation times and lower CPU consumption, making it more efficient than the legacy SDK.
- New Features: Access to Parameter Stores.
- Future Support: All new features and improvements are only available in Go Core.
- Maintenance: The legacy Go SDK is in maintenance mode and only receives critical bug fixes.
Installation differences
Legacy Go SDK
go get github.com/statsig-io/go-sdk
Go Core SDK
Go Core requires the new package and additional setup. Install the latest version of the SDK:
go get github.com/statsig-io/statsig-server-core/statsig-go@latest
Run the following commands to install the necessary binaries and set environment variables:
go install github.com/statsig-io/statsig-server-core/statsig-go/cmd/post-install@latest
post-install
Follow the prompts to set the environment variables using the statsig.env or statsig.env.ps1 file generated during the post-install script.
source /Users/Your-User-Name/.statsig_env
Add the variables to your .bashrc, .zshrc, or .ps1 file to load them automatically.
API differences
Key package and import changes
| Feature | Legacy Go SDK | Go Core SDK |
|---|---|---|
| Import | github.com/statsig-io/go-sdk | github.com/statsig-io/statsig-server-core/statsig-go/src |
| Main Package | statsig | statsig |
| Initialization | Static statsig.Initialize() | Instance-based statsig.Initialize() |
| Options | &Options{} | statsig.NewStatsigOptionsBuilder().With*().Build() |
| User Creation | statsig.User{} | statsig.NewStatsigUserBuilder().With*().Build() |
Initialization
import (
statsig "github.com/statsig-io/go-sdk"
)
statsig.Initialize("server-secret-key")
// Or, if you want to initialize with certain options
statsig.InitializeWithOptions("server-secret-key", &Options{Environment: Environment{Tier: "staging"}})
Checking gates
import (
statsig "github.com/statsig-io/go-sdk"
)
user := statsig.User{
UserID: "123",
Email: "test@example.com",
}
// Check if a gate is enabled
enabled := statsig.CheckGate(user, "my_gate")
Getting dynamic configs
import (
statsig "github.com/statsig-io/go-sdk"
)
user := statsig.User{
UserID: "123",
Email: "test@example.com",
}
// Get a dynamic config
config := statsig.GetConfig(user, "my_config")
value := config.Get("key", "default_value")
Getting experiments
import (
statsig "github.com/statsig-io/go-sdk"
)
user := statsig.User{
UserID: "123",
Email: "test@example.com",
}
// Get an experiment
experiment := statsig.GetExperiment(user, "my_experiment")
Logging events
import (
statsig "github.com/statsig-io/go-sdk"
)
user := statsig.User{
UserID: "123",
Email: "test@example.com",
}
// Log an event
statsig.LogEvent(Event{
User: user,
EventName: "add_to_cart",
Value: "SKU_12345",
Metadata: map[string]string{"price": "9.99","item_name": "diet_coke_48_pack"},
})
Key migration steps
Update Dependencies: Change from
github.com/statsig-io/go-sdktogithub.com/statsig-io/statsig-server-core/statsig-go/srcRun Post-Install: Execute the post-install script to set up environment variables and pull down the latest version of the Rust core library.
Update Initialization:
- Use the builder pattern to create user and options.
- Replace
statsig.User{}withstatsig.NewStatsigUserBuilder().With*().Build(). - Initialize with
statsig.NewStatsig()and callInitialize().
Test Thoroughly:
- Verify all feature gates, experiments, and configs work as expected.
- Check that event logging is functioning correctly.
New features available in Go Core
- Parameter Stores: Access to dynamic parameter management.
- Improved Performance: 5-10x faster evaluation times.
- Better Error Handling: More robust error management.
Need help?
If you encounter any issues during migration, reach out in Slack or go to the GitHub repository for the latest updates and examples.Was this helpful?