Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
.PHONY: build test test-example-1 clean setup-monorepo update-monorepo
.PHONY: build test test-openfeature test-example-1 clean setup-monorepo update-monorepo

build:
mkdir -p build
go build -o build/featurevisor-go cmd/main.go

test:
go test ./...
$(MAKE) test-openfeature

test-openfeature:
(cd openfeature && GOWORK=off go test ./...)

test-example-1:
go test ./...
$(MAKE) test
go run cmd/main.go test --projectDirectoryPath=../featurevisor/examples/example-1 --onlyFailures

clean:
Expand Down
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ See example application [here](https://github.com/featurevisor/featurevisor-exam
- [Registering modules](#registering-modules)
- [Child instance](#child-instance)
- [Close](#close)
- [OpenFeature](#openfeature)
- [CLI usage](#cli-usage)
- [Test](#test)
- [Benchmark](#benchmark)
Expand Down Expand Up @@ -839,6 +840,61 @@ go run cmd/main.go assess-distribution \
--n=1000
```

## OpenFeature

The OpenFeature provider is a separate Go module, so applications that do not use OpenFeature do not receive its dependencies:

```bash
go get github.com/featurevisor/featurevisor-go/openfeature
```

```go
import (
"context"

featurevisor "github.com/featurevisor/featurevisor-go"
featurevisorof "github.com/featurevisor/featurevisor-go/openfeature"
of "github.com/open-feature/go-sdk/openfeature"
)

provider := featurevisorof.NewProvider(featurevisorof.Options{
FeaturevisorOptions: featurevisor.FeaturevisorOptions{
Datafile: datafileContent,
},
})

if err := of.SetProviderAndWait(provider); err != nil {
panic(err)
}

client := of.NewClient("")
enabled, err := client.BooleanValue(
context.Background(),
"checkout",
false,
of.NewEvaluationContext("user-123", map[string]any{"country": "nl"}),
)
```

Use `checkout` for a flag, `checkout:variation` for its variation, and `checkout:title` for its `title` variable. Boolean variables use the boolean resolver. Arrays, objects, and JSON variables use the object resolver.

OpenFeature's targeting key maps to `userId` by default. `TargetingKeyField`, `KeySeparator`, and `VariationKey` can customize the mapping. The provider's separate module follows the Go version requirement of the official OpenFeature Go SDK.

You can also reuse an existing Featurevisor instance:

```go
fv := featurevisor.CreateFeaturevisor(featurevisor.FeaturevisorOptions{
Datafile: datafileContent,
})
provider := featurevisorof.NewProvider(featurevisorof.Options{
Featurevisor: fv,
})
```

The caller owns an instance passed this way. Provider shutdown does not close it. Call `fv.Close()` when every consumer is finished with it. When the provider creates the instance from `FeaturevisorOptions`, the provider owns and closes it. If both fields are supplied, `Featurevisor` takes precedence over `FeaturevisorOptions`.

See the [OpenFeature provider guide](https://featurevisor.com/docs/sdks/openfeature/) for resolution reasons, errors, metadata, tracking, lifecycle, and providers for other languages.

<!-- FEATUREVISOR_DOCS_END -->

## Development of this package
Expand Down
15 changes: 15 additions & 0 deletions openfeature/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module github.com/featurevisor/featurevisor-go/openfeature

go 1.25.0

require (
github.com/featurevisor/featurevisor-go v1.0.0
github.com/open-feature/go-sdk v1.17.2
)

require (
github.com/go-logr/logr v1.4.3 // indirect
go.uber.org/mock v0.6.0 // indirect
)

replace github.com/featurevisor/featurevisor-go => ..
16 changes: 16 additions & 0 deletions openfeature/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/open-feature/go-sdk v1.17.2 h1:pTdeNks/hgnPrlqdgtFwltnIron1oOxqg4FmLlirJlY=
github.com/open-feature/go-sdk v1.17.2/go.mod h1:kTMCquVtck18XdSCI6rBoNFEBLvkOy4Tphu2pV8bq34=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU=
golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8=
golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading
Loading