A Go SDK for Molasses. It allows you to evaluate a user's status for a feature. It also helps simplify logging events for A/B testing.
The SDK uses SSE to communicate with the Molasses Application. Once initialized, it takes microseconds to evaluate if a user is active. When you update a feature on Molasses, it sends that update to all of your clients through SSE and users would start experiencing that change instantly.
1go get github.com/molassesapp/molasses-go
Start by initializing the client with an APIKey
. This begins the polling for any feature updates. The updates happen every 15 seconds.
1client, err := molasses.Init(molasses.ClientOptions{2APIKey: os.Getenv("MOLASSES_API_KEY"),3})
If you decide to automatically track analytics events (experiment started, experiment success) you can turn them off by setting the AutoSendEvents
field to true
1client, err := molasses.Init(molasses.ClientOptions{2APIKey: os.Getenv("MOLASSES_API_KEY"),3AutoSendEvents: true,4})
You can call isActive
with the key name and optionally a user's information. The ID field is used to determine whether a user is part of a percentage of users. If you have other constraints based on user params you can pass those in the Params
field.
1client.IsActive("TEST_FEATURE_FOR_USER", molasses.User{2ID: "baz",3Params: map[string]string{4"teamId": "12356",5},6})
You can check if a feature is active for a user who is anonymous by just calling isActive
with the key. You won't be able to do percentage roll outs or track that user's behavior.
1client.IsActive("TEST_FEATURE_FOR_USER")
If you want to track any event call the Track
method. Track
takes the event's name, the molasses User and any additional parameters for the event.
1client.Track("Checkout Submitted", molasses.User{2ID: "baz",3Params: map[string]interface{}{4"teamId": "12356",5},6}, map[string]interface{}{7"version": "v2.3.0"8})
To track the start of an experiment, you can call ExperimentStarted
. ExperimentStarted takes the feature's name, the molasses User and any additional parameters for the event.
1client.ExperimentStarted("GOOGLE_SSO", molasses.User{2ID: "baz",3Params: map[string]interface{}{4"teamId": "12356",5},6}, map[string]interface{}{7"version": "v2.3.0"8})
To track whether an experiment was successful you can call ExperimentSuccess
. ExperimentSuccess takes the feature's name, the molasses User and any additional parameters for the event.
1client.ExperimentSuccess("GOOGLE_SSO", molasses.User{2ID: "baz",3Params: map[string]interface{}{4"teamId": "12356",5},6}, map[string]interface{}{7"version": "v2.3.0"8})
1import (2"fmt"3"os"45"github.com/molassessapp/molasses-go"6)78func main() {9client, err := molasses.Init(molasses.ClientOptions{10APIKey: os.Getenv("MOLASSES_API_KEY"),11})1213if client.IsActive("New Checkout") {14fmt.Println("we are a go")15} else {16fmt.Println("we are a no go")17}1819if client.IsActive("Another feature", molasses.User{20ID: "baz",21Params: map[string]interface{}{22"teamId": "12356",23},24}) {25fmt.Println("we are a go")26} else {27fmt.Println("we are a no go")28}29}