Git Product home page Git Product logo

confidence-openfeature-provider-go's Introduction

Confidence OpenFeature Go Provider

This repo contains the OpenFeature Go flag provider for Confidence.

OpenFeature

Before starting to use the provider, it can be helpful to read through the general OpenFeature docs and get familiar with the concepts.

Adding the dependency

require (
	github.com/spotify/confidence-openfeature-provider-go v0.1.6
)

It's also important to add the underlying OpenFeature SDK dependency:

require (
	github.com/open-feature/go-sdk v1.7.0
)

Creating and using the flag provider

Below is an example for how to create a OpenFeature client using the Confidence flag provider, and then resolve a flag with a boolean attribute. The provider is configured with an api key and a region, which will determine where it will send the resolving requests.

The flag will be applied immediately, meaning that Confidence will count the targeted user as having received the treatment.

You can retrieve attributes on the flag variant using property dot notation, meaning test-flag.boolean-key will retrieve the attribute boolean-key on the flag test-flag.

You can also use only the flag name test-flag and retrieve all values as a map with client.ObjectValue().

The flag's schema is validated against the requested data type, and if it doesn't match it will fall back to the default value.

import (
    "github.com/open-feature/go-sdk/pkg/openfeature"
    confidence "github.com/spotify/confidence-openfeature-provider-go/pkg/provider"
)

provider, err := confidence.NewFlagProvider(confidence.APIConfig{APIKey: "apiKey", Region: confidence.APIRegionEU})

if err != nil {
    // handle error	
}

openfeature.SetProvider(provider)
client := openfeature.NewClient("testApp")
	
attributes := make(map[string]interface{})
attributes["country"] = "SE"
attributes["plan"] = "premium"
attributes["user_id"] = "user1"

boolValue, error := client.BooleanValue(context.Background(), "test-flag.boolean-key", false, 
	openfeature.NewEvaluationContext("", attributes))

Demo app

To run the demo app, replace the CLIENT_SECRET with client secret setup in the Confidence console, the flags with existing flags and execute the app with cd demo && go run GoDemoApp.go.

confidence-openfeature-provider-go's People

Contributors

fabriziodemaria avatar vahidlazio avatar github-actions[bot] avatar valkyrie00 avatar nicklasl avatar nickybondarenko avatar dzolotusky avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.