We have moved the Flipt OpenFeature Provider (Go) to the official OpenFeature Go Contrib repository. You can find the latest version of the Flipt OpenFeature Provider (Go) at: https://github.com/open-feature/go-sdk-contrib/tree/main/providers/flipt.
We will continue to maintain the Flipt OpenFeature Provider (Go) in the OpenFeature Go Contrib repository. Please open any issues or pull requests there.
In the future, we will be archiving this repository and eventually removing it.
This repository and package provides a Flipt OpenFeature Provider for interacting with the Flipt service backend using the OpenFeature Go SDK.
From the OpenFeature Specification:
Providers are the "translator" between the flag evaluation calls made in application code, and the flag management system that stores flags and in some cases evaluates flags.
- Go 1.20+
- A running instance of Flipt
Version v0.2.0 of this client correlates Boolean flag evaluations to Boolean flag types on the Flipt server. Upgrading to this version will require you to convert your flags that were using Boolean evaluation to the Boolean flag type on the Flipt server.
Version v0.1.5 of this client introduced a change to use a newer version of the Flipt API which requires use of the namespace
parameter. This is to support the new namespace functionality added to Flipt v1.20.0.
This client uses the default
namespace by default. If you are using a different namespace, you will need to set the namespace
parameter when creating the provider:
provider := flipt.NewProvider(flipt.ForNamespace("my-namespace"))
go get go.flipt.io/flipt-openfeature-provider
package main
import (
"context"
"go.flipt.io/flipt-openfeature-provider/pkg/provider/flipt"
"github.com/open-feature/go-sdk/pkg/openfeature"
)
func main() {
// http://localhost:8080 is the default Flipt address
openfeature.SetProvider(flipt.NewProvider())
client := openfeature.NewClient("my-app")
value, err := client.BooleanValue(context.Background(), "v2_enabled", false, openfeature.EvaluationContext{
TargetingKey: "[email protected]",
Attributes: map[string]interface{}{
"favorite_color": "blue",
},
})
if err != nil {
panic(err)
}
if value {
// do something
} else {
// do something else
}
}
The Flipt provider allows you to communicate with Flipt over either HTTP(S) or GRPC, depending on the address provided.
provider := flipt.NewProvider(flipt.WithAddress("https://localhost:443"))
provider := flipt.NewProvider(flipt.WithAddress("unix:///path/to/socket"))
type Token string
func (t Token) ClientToken() (string, error) {
return t, nil
}
provider := flipt.NewProvider(
flipt.WithAddress("grpc://localhost:9000"),
flipt.WithCertificatePath("/path/to/cert.pem"), // optional
flipt.WithClientProvider(Token("a-client-token")), // optional
)
provider := flipt.NewProvider(
flipt.WithAddress("unix:///path/to/socket"),
)