Hypertune
  • Introduction
  • Getting Started
    • Set up Hypertune
    • Next.js (App Router) quickstart
    • Next.js (Pages Router) quickstart
    • React quickstart
    • Remix quickstart
    • Gatsby quickstart
    • Vue quickstart
    • Nuxt quickstart
    • Node.js quickstart
    • React Native quickstart
    • JavaScript quickstart
    • Python quickstart
    • Rust quickstart
    • Go quickstart
    • Web quickstart
    • GraphQL quickstart
  • Example apps
    • Next.js and Vercel example app
  • Concepts
    • Architecture
    • Project
    • Schema
    • Flag lifecycle
    • Logic
    • Variables
    • Splits
    • A/B tests
    • Staged rollouts
    • Multivariate tests
    • Machine learning loops
    • Events
    • Funnels
    • Hypertune Edge
    • Reduction
    • SDKs
    • GraphQL API
    • Git-style version control
    • App configuration
  • Use Cases
    • Feature flags and A/B testing
    • Landing page optimization
    • In-app content management
    • Pricing plan management
    • Permissions, rules and limits
    • Optimizing magic numbers
    • Backend configuration
    • Product analytics
  • Integrations
    • Vercel Edge Config integration
    • Google Analytics integration
    • Segment integration
    • Webhooks
      • Creating webhooks
      • Handling webhooks
  • SDK Reference
    • Installation
    • Type-safe client generation
    • Initialization
    • Build-time logic snapshot
    • Hard-coded fallbacks
    • Local-only, offline mode
    • Hydrate from your own server
    • Wait for server initialization
    • Provide targeting attributes
    • Local, synchronous evaluation
    • Remote logging
    • Getting flag updates
    • Serverless environments
    • Vercel Edge Config
    • Custom logging
    • Shutting down
Powered by GitBook
On this page
  • 1. Install hypertune-go-gen
  • 2. Generate the client
  • 3. Use the client
  • That's it
  1. Getting Started

Go quickstart

1. Install 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: "hi@test.com",
			},
		},
	})

	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.

PreviousRust quickstartNextWeb quickstart

Last updated 2 months ago