Skip to content

Latest commit

 

History

History
74 lines (58 loc) · 2.18 KB

README.md

File metadata and controls

74 lines (58 loc) · 2.18 KB

Unofficial Harness OpenFeature GO Provider

Harness OpenFeature Provider can provide usage for Harness via OpenFeature GO SDK.

Installation

To use the Harness provider, you'll need to install Harness Go client and Harness provider. You can install the packages using the following command

go get github.com/harness/ff-golang-server-sdk
go get github.com/open-feature/go-sdk-contrib/providers/harness

Concepts

  • Provider Object evaluation gets Harness JSON evaluation.
  • Other provider types evaluation gets Harness matching type evaluation.

Usage

Harness OpenFeature Provider is using Harness GO SDK.

Evaluation Context

Evaluation Context is mapped to Harness target. OpenFeature targetingKey is mapped to Identifier, Name is mapped to Name and other fields are mapped to Attributes fields.

Usage Example

import (
  harness "github.com/harness/ff-golang-server-sdk/client"
  harnessProvider "github.com/open-feature/go-sdk-contrib/providers/harness/pkg"
)

providerConfig := harnessProvider.ProviderConfig{
    Options: []harness.ConfigOption{
        harness.WithWaitForInitialized(true),
        harness.WithURL(URL),
        harness.WithStreamEnabled(false),
        harness.WithHTTPClient(http.DefaultClient),
        harness.WithStoreEnabled(false),
    },
    SdkKey: ValidSDKKey,
}

provider, err := harnessProvider.NewProvider(providerConfig)
if err != nil {
    t.Fail()
}
err = provider.Init(of.EvaluationContext{})
if err != nil {
    t.Fail()
}

ctx := context.Background()

of.SetProvider(provider)
ofClient := of.NewClient("my-app")

evalCtx := of.NewEvaluationContext(
    "john",
    map[string]interface{}{
        "Firstname": "John",
        "Lastname":  "Doe",
        "Email":     "[email protected]",
    },
)
enabled, err := ofClient.BooleanValue(context.Background(), "TestTrueOn", false, evalCtx)
if enabled == false {
    t.Fatalf("Expected feature to be enabled")
}

See provider_test.go for more information.