This SDK provides a convenient way to interact with the RocketFlag API from your Go applications.
go get github.com/rocketflag/go-sdk
package main
import (
"context"
"fmt"
"log"
rocketflag "github.com/rocketflag/go-sdk"
)
func main() {
rf := rocketflag.NewClient()
// Example: Get a single flag
flag, err := rf.GetFlag("flag-id", rocketflag.UserContext{})
if err != nil {
log.Fatal(err)
}
fmt.Println("Flag:", flag)
}
If you want to use a cohort and only enable flags for certain users, you'll need to setup the accepted cohorts in the console. Once done, you can pass the cohort like so with the SDK:
flag, err := rf.GetFlag("flag-id", rocketflag.UserContext{"cohort": "user@example.com"})
You can pass in http clients if you use them or have custom ones. Eg:
import (
"net/http"
)
customHttpClient := &http.Client{}
client := rocketflag.NewClient(WithHTTPClient(customHttpClient))
By default, RocketFlag will use the latest API version that the SDK knows about. Right now, this is version 1. You can override this if you prefer as so:
client := rocketflag.NewClient(WithVersion("v2"))
By default, RocketFlag will use the RocketFlag API. This is https://api.rocketflag.app. You can override this if you prefer as so:
client := rocketflag.NewClient(WithAPIURL("https://api.example.com"))
client := rocketflag.NewClient(
WithHTTPClient(customHttpClient),
WithVersion("v2"),
WithAPIURL("https://api.example.com")
)