Skip to content

Latest commit

 

History

History
 
 

flipt-client-go

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Flipt Client Go

Client tag Client tag (musl) Go Reference

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

Installation

go get go.flipt.io/flipt-client

How Does It Work?

The flipt-client-go library is a wrapper around the flipt-engine-ffi library.

All evaluation happens within the SDK, using the shared library built from the flipt-engine-ffi library.

Because the evaluation happens within the SDK, the SDKs can be used in environments where the Flipt server is not available or reachable after the initial data is fetched.

Data Fetching

Upon instantiation, the flipt-client-go library will fetch the flag state from the Flipt server and store it in memory. This means that the first time you use the SDK, it will make a request to the Flipt server.

Polling (Default)

By default, the SDK will poll the Flipt server for new flag state at a regular interval. This interval can be configured using the WithUpdateInterval option when constructing a client. The default interval is 120 seconds.

Streaming (Flipt Cloud Only)

Flipt Cloud users can use the streaming fetch method to stream flag state changes from the Flipt server to the SDK.

When in streaming mode, the SDK will connect to the Flipt server and open a persistent connection that will remain open until the client is closed. The SDK will then receive flag state changes in real-time.

Supported Architectures

This SDK currently supports the following OSes/architectures:

  • Linux x86_64
  • Linux x86_64 (musl)
  • Linux arm64
  • Linux arm64 (musl)
  • MacOS x86_64
  • MacOS arm64
  • Windows x86_64

Glibc vs Musl

Most Linux distributions use Glibc, but some distributions like Alpine Linux use Musl. If you are using Alpine Linux, you will need to install the musl tagged version of the client.

Example:

go install go.flipt.io/[email protected]

See flipt-client-sdks #141 for more information.

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() {
  evaluationClient, err := flipt.NewEvaluationClient()
  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)
}

Client Options

The NewClient constructor accepts a variadic number of ClientOption functions that can be used to configure the client. The available options are:

  • WithNamespace: The namespace to fetch flag state from. If not provided, the client will default to the default namespace.
  • WithURL: The URL of the upstream Flipt instance. If not provided, the client will default to http://localhost:8080.
  • WithUpdateInterval: The interval (in seconds) in which to fetch new flag state. If not provided, the client will default to 120 seconds.
  • With{Method}Authentication: The authentication strategy to use when communicating with the upstream Flipt instance. If not provided, the client will default to no authentication. See the Authentication section for more information.
  • WithReference: The reference to use when fetching flag state. If not provided, reference will not be used.
  • WithFetchMode: The fetch mode to use when fetching flag state. If not provided, the client will default to polling.

Authentication

The Client supports the following authentication strategies:

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()

Contributing

Contributions are welcome! Please feel free to open an issue or submit a Pull Request.

License

This project is licensed under the MIT License.