Trouble getting started with Open Feature Go provider

I’m trying to get started with openfeature go provider but running into some issues, its possible there is something wrong with my environment. When I run

go get github.com/open-feature/go-sdk-contrib/providers/flipt

and then go mod tidy

I see this error:

go: finding module for package github.com/open-feature/go-sdk-contrib/providers/flipt
go: snippetbox.levlaz.org/cmd/web imports
        github.com/open-feature/go-sdk-contrib/providers/flipt: module github.com/open-feature/go-sdk-contrib/providers/flipt@latest found (v0.1.1), but does not contain package github.com/open-feature/go-sdk-contrib/providers/flipt

Any ideas?

yeah I just reproduced. let me look into it and ping the openfeature team and will get back to you

thanks for raising this!

1 Like

So the problem is that the actual provider is nested within this module in /pkg/provider. So you have to do the following import to get it:

package main

import (
	"context"

	flipt "github.com/open-feature/go-sdk-contrib/providers/flipt/pkg/provider"
	"github.com/open-feature/go-sdk/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.NewEvaluationContext(
		"tim@apple.com",
		map[string]interface{}{
			"favorite_color": "blue",
		},
	))

	if err != nil {
		panic(err)
	}

	if value {
		// do something
	} else {
		// do something else
	}
}

I just popped open a PR to address this chore(providers/flipt): update README with correct provider import statement by GeorgeMac · Pull Request #496 · open-feature/go-sdk-contrib · GitHub

1 Like

@levlaz this is merged now in the open-feature repo chore(providers/flipt): update README with correct provider import st… · open-feature/go-sdk-contrib@0ac382e · GitHub

after updating the import statement should work now