Go quickstart
1. Install hypertune-go-gen
hypertune-go-gen
Once you have a Go application ready, install the hypertune-go-gen
tool by running:
go get -tool github.com/hypertunehq/hypertune-go/cmd/hypertune-go-gen
2. Generate the client
Set the HYPERTUNE_TOKEN
environment variable to your project token which you can find in the Settings tab of your project.
Then generate the client by running:
go tool hypertune-go-gen --token=${HYPERTUNE_TOKEN} --outputFileDir=pkg/hypertune
Alternatively, you can add the following go generate
directive to one of your Go files to automatically re-generate the client when you run go generate ./...
:
//go:generate go tool hypertune-go-gen --token=${HYPERTUNE_TOKEN} --outputFileDir=pkg/hypertune
3. Use the client
Finally, instantiate the client and evaluate your flags:
package main
import (
"fmt"
"log"
"os"
// Update to your project path.
"github.com/myTeam/myProject/pkg/hypertune"
)
func main() {
if err := run(); err != nil {
log.Fatal(err)
}
}
func run() error {
var token = os.Getenv("HYPERTUNE_TOKEN")
source, err := hypertune.CreateSource(&token)
if err != nil {
return err
}
defer source.Close()
source.WaitForInitialization()
rootNode := source.Root(hypertune.RootArgs{
Context: hypertune.Context{
Environment: hypertune.Development,
User: hypertune.User{
Id: "test_id",
Name: "Test",
Email: "[email protected]",
},
},
})
fmt.Printf("ExampleFlag: %v\n", rootNode.ExampleFlag(false))
return nil
}
That's it
Now you can update the logic for ExampleFlag
from the Hypertune UI without updating your code or waiting for a new build, deployment, app release or service restart.
To add a new flag, create it in the Hypertune UI then regenerate the client.
Last updated