Note
This is a read-only repository that houses the release of the flipt-client-go
library due to how Go modules work. Please open any issues regarding the library in the flipt-client-sdks repository.
The flipt-client-go
library contains the Go source code for the Flipt client-side evaluation client.
go get go.flipt.io/flipt-client
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.
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.
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.
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.
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
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.
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)
}
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 thedefault
namespace.WithURL
: The URL of the upstream Flipt instance. If not provided, the client will default tohttp://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.
The Client
supports the following authentication strategies:
- No Authentication (default)
- Client Token Authentication
- JWT Authentication
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()
Contributions are welcome! Please open an issue or submit a Pull Request in the flipt-client-sdks repository.
This project is licensed under the MIT License.