Skip to content

Latest commit

 

History

History
64 lines (45 loc) · 1.87 KB

README.md

File metadata and controls

64 lines (45 loc) · 1.87 KB

Flipt Client Go

Client tag

Note

This is a read-only repository used to house the release of the flipt-client-go library due to how Go modules works. Please open any issues regarding the library in the flipt-client-sdks repository.

The flipt-client-go directory contains the Go source code for the Flipt client-side evaluation client.

Installation

go get go.flipt.io/flipt-client

Usage

In your Go code you can import this client and use it as so:

package main

import (
  "context"
  "fmt"
  "log"

  flipt "go.flipt.io/flipt-client"
)

func main() {
  // The NewClient() accepts options which are the following:
  // flipt.WithNamespace(string): configures which namespace you will be making evaluations on
  // flipt.WithURL(string): configures which upstream Flipt data should be fetched from
  // flipt.WithUpdateInterval(int): configures how often data should be fetched from the upstream
  // flipt.WithAuthToken(string): configures an auth token if your upstream Flipt instance requires it
  evaluationClient, err := flipt.NewClient()
  if err != nil {
    log.Fatal(err)
  }

  defer evaluationClient.Close()

  variantResult, err := evaluationClient.EvaluateVariant(context.Background(), "flag1", "someentity", map[string]string{
    "fizz": "buzz",
  })

  if err != nil {
    log.Fatal(err)
  }

  fmt.Println(*variantResult.Result)
}

Memory Management

The engine that is allocated on the Rust side to compute evaluations for flag state will not be properly deallocated unless you call the Close() method on a Client instance.

Please be sure to do this to avoid leaking memory!

defer evaluationClient.Close()