Molasses

Go Sdk#

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.

Install#

1
go get github.com/molassesapp/molasses-go

Usage#

Initialization#

Start by initializing the client with an APIKey. This begins the polling for any feature updates. The updates happen every 15 seconds.

go
1
client, err := molasses.Init(molasses.ClientOptions{
2
APIKey: 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

go
1
client, err := molasses.Init(molasses.ClientOptions{
2
APIKey: os.Getenv("MOLASSES_API_KEY"),
3
AutoSendEvents: true,
4
})

Check if feature is active#

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.

go
1
client.IsActive("TEST_FEATURE_FOR_USER", molasses.User{
2
ID: "baz",
3
Params: 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.

go
1
client.IsActive("TEST_FEATURE_FOR_USER")

Experiments#

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.

go
1
client.ExperimentStarted("GOOGLE_SSO", molasses.User{
2
ID: "baz",
3
Params: map[string]string{s
4
"teamId": "12356",
5
},
6
}, map[string]string{
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.

go
1
client.ExperimentSuccess("GOOGLE_SSO", molasses.User{
2
ID: "baz",
3
Params: map[string]string{
4
"teamId": "12356",
5
},
6
}, map[string]string{
7
"version": "v2.3.0"
8
})

Example#

go
1
import (
2
"fmt"
3
"os"
4
5
"github.com/molassessapp/molasses-go"
6
)
7
8
func main() {
9
client, err := molasses.Init(molasses.ClientOptions{
10
APIKey: os.Getenv("MOLASSES_API_KEY"),
11
})
12
13
if client.IsActive("New Checkout") {
14
fmt.Println("we are a go")
15
} else {
16
fmt.Println("we are a no go")
17
}
18
19
if client.IsActive("Another feature", molasses.User{
20
ID: "baz",
21
Params: map[string]string{
22
"teamId": "12356",
23
},
24
}) {
25
fmt.Println("we are a go")
26
} else {
27
fmt.Println("we are a no go")
28
}
29
}
Go Sdk