octopus

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Octopus Deploy OpenFeature provider for Go

CI build

The Octopus Deploy OpenFeature provider for Go, to be used with the OpenFeature Go SDK.

This provider is for server-side applications. It isn't intended for clients such as browser or desktop applications.

About Octopus Deploy

Octopus Deploy is a sophisticated, best-of-breed continuous delivery (CD) platform for modern software teams. Octopus offers powerful release orchestration, deployment automation, and runbook automation, while handling the scale, complexity and governance expectations of even the largest organizations with the most complex deployment challenges.

Supported Go Versions

This provider supports Go 1.26 and above. It follows the minimum Go version of the OpenFeature Go SDK, so the minimum moves up when the SDK's does.

Getting Started

Installation
go get github.com/open-feature/go-sdk github.com/OctopusDeploy/openfeature-provider-go
Usage
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	octopus "github.com/OctopusDeploy/openfeature-provider-go"
	"github.com/open-feature/go-sdk/openfeature"
)

func main() {
	productMetadata, err := octopus.NewProductMetadataWithVersion("YourProductName", "1.0.0")
	if err != nil {
		log.Fatal(err)
	}

	configuration := octopus.NewFeatureConfiguration(os.Getenv("OCTOPUS_FEATURE_FLAGS_CLIENT_IDENTIFIER"), productMetadata)

	provider, err := octopus.NewFeatureProvider(configuration)
	if err != nil {
		log.Fatal(err)
	}

	// Wait for the flags at startup, so your first evaluations don't get the default value.
	if err := openfeature.SetProviderAndWait(provider); err != nil {
		log.Fatal(err)
	}
	defer openfeature.Shutdown()

	client := openfeature.NewDefaultClient()

	enabled, _ := client.BooleanValue(context.Background(), "to-the-moon-feature", false, openfeature.EvaluationContext{})
	if enabled {
		fmt.Println("🚀🚀🚀")
	}
}

This example is compiled with the tests, in example_test.go.

Octopus feature flags are boolean, so evaluate them with BooleanValue. StringValue, FloatValue, IntValue and ObjectValue return your default value with a TYPE_MISMATCH error code, or FLAG_NOT_FOUND if the flag doesn't exist.

Targeting rules match against string attributes in the evaluation context, and percentage rollouts use its targeting key. Without a targeting key, a caller is only included in a rollout set to 100%.

The provider fetches flags when it initializes. If it can't retrieve them, SetProviderAndWait still doesn't return an error. The provider becomes ready, and every evaluation returns your default value with a FLAG_NOT_FOUND error code until a fetch succeeds.

After that, it checks for changes every CacheDuration and fetches the flags again only when they have changed. If a check fails, the provider keeps evaluating against the flags it already has and tries again at the next interval.

openfeature.Shutdown() stops the polling and closes the idle connections of the HTTP client the provider created. It never closes an HTTPClient you provide.

For information on using the OpenFeature client, refer to the OpenFeature Go SDK documentation.

Configuration

NewFeatureConfiguration sets the required options and the defaults. Set any optional fields on the configuration before you pass it to NewFeatureProvider. The provider keeps its own copy, so later changes have no effect.

Option Required Description
ClientIdentifier Yes The client identifier from the Octopus variable Octopus.FeatureFlags.ClientIdentifier. Must not contain line breaks or other control characters, so remove any trailing newline when you read it from a file.
ProductMetadata Yes The name and, optionally, version of your application, sent to Octopus for telemetry. Create it with NewProductMetadata or NewProductMetadataWithVersion.
CacheDuration No How long between checks for changed flags. Defaults to 1 minute. Must be greater than 0.
RequestTimeout No How long a request to Octopus may take before it's abandoned. Defaults to 10 seconds. Must be greater than 0, and should be well under CacheDuration.
ReleaseVersionOverride No Overrides the release version embedded in the client identifier. Must not contain line breaks or other control characters.
Logger No A *slog.Logger for the provider's own log messages. If it's nil, the provider logs nothing.
HTTPClient No The *http.Client for requests to Octopus. If it's nil, the provider creates its own.
ServerURI No The base URI of the Octopus feature flags service, for testing against a non-production service. Leave it unset in production. Defaults to https://features.octopus.com. Must be an absolute http or https URI.

Provide an HTTPClient to add tracing, a proxy or custom TLS. For example, to trace requests with OpenTelemetry:

configuration.HTTPClient = &http.Client{Transport: otelhttp.NewTransport(http.DefaultTransport)}

Contributing

See CONTRIBUTING.md to build and test locally, and RELEASING.md for how the provider is released.

License

Apache 2.0

Documentation

Overview

Example

The README's usage section is a copy of this example. Keep the two in step.

package main

import (
	"context"
	"fmt"
	"log"
	"os"

	octopus "github.com/OctopusDeploy/openfeature-provider-go"
	"github.com/open-feature/go-sdk/openfeature"
)

func main() {
	productMetadata, err := octopus.NewProductMetadataWithVersion("YourProductName", "1.0.0")
	if err != nil {
		log.Fatal(err)
	}

	configuration := octopus.NewFeatureConfiguration(os.Getenv("OCTOPUS_FEATURE_FLAGS_CLIENT_IDENTIFIER"), productMetadata)

	provider, err := octopus.NewFeatureProvider(configuration)
	if err != nil {
		log.Fatal(err)
	}

	// Wait for the flags at startup, so your first evaluations don't get the default value.
	if err := openfeature.SetProviderAndWait(provider); err != nil {
		log.Fatal(err)
	}
	defer openfeature.Shutdown()

	client := openfeature.NewDefaultClient()

	enabled, _ := client.BooleanValue(context.Background(), "to-the-moon-feature", false, openfeature.EvaluationContext{})
	if enabled {
		fmt.Println("🚀🚀🚀")
	}
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FeatureConfiguration

type FeatureConfiguration struct {
	// ClientIdentifier is the value of the Octopus variable
	// Octopus.FeatureFlags.ClientIdentifier.
	ClientIdentifier string

	// ProductMetadata describes the product using the provider.
	ProductMetadata ProductMetadata

	// CacheDuration is how often the provider polls the feature flags service
	// for new feature flag evaluations. Defaults to 1 minute.
	CacheDuration time.Duration

	// RequestTimeout is how long a request to the feature flags service may
	// take before it is abandoned. It covers the whole request, connecting
	// included, and should be kept well under CacheDuration so a stalled
	// request can't hold up the next poll. Defaults to 10 seconds.
	RequestTimeout time.Duration

	// ReleaseVersionOverride overrides the application release version
	// embedded in ClientIdentifier. It is sent to the feature flags service
	// only when not empty.
	ReleaseVersionOverride string

	// Logger receives the provider's log output. Nil means the provider logs
	// nothing.
	Logger *slog.Logger

	// HTTPClient is used for requests to the feature flags service, for
	// example to configure a proxy, TLS or instrumentation. Nil means the
	// provider creates and owns its own client. The provider never closes a
	// client set here.
	HTTPClient *http.Client

	// ServerURI is the base URI of the feature flags service, for testing
	// against a non-production service. Leave it unset in production. It must
	// be an absolute http or https URI. Defaults to https://features.octopus.com.
	ServerURI string
}

FeatureConfiguration configures a FeatureProvider. Create one with NewFeatureConfiguration, then assign any optional fields before passing it to NewFeatureProvider.

func NewFeatureConfiguration

func NewFeatureConfiguration(clientIdentifier string, productMetadata ProductMetadata) *FeatureConfiguration

NewFeatureConfiguration returns a configuration with the required values set and every optional field at its default.

type FeatureProvider

type FeatureProvider struct {
	// contains filtered or unexported fields
}

FeatureProvider is an OpenFeature provider for Octopus feature flags. Create one with NewFeatureProvider and register it with the OpenFeature SDK.

func NewFeatureProvider

func NewFeatureProvider(configuration *FeatureConfiguration) (*FeatureProvider, error)

NewFeatureProvider returns a provider for the given configuration. It returns an error if ClientIdentifier is empty, ClientIdentifier or ReleaseVersionOverride contains a line break or other control character, ProductMetadata wasn't created with one of its constructors, CacheDuration or RequestTimeout isn't positive, or ServerURI is set but isn't an absolute http or https URI. The provider keeps its own copy, so changes to configuration afterwards have no effect on it. It makes no requests until the SDK initializes it.

func (*FeatureProvider) BooleanEvaluation

func (p *FeatureProvider) BooleanEvaluation(_ context.Context, flag string, defaultValue bool, flatCtx openfeature.FlattenedContext) openfeature.BoolResolutionDetail

BooleanEvaluation implements openfeature.FeatureProvider.

func (*FeatureProvider) FloatEvaluation

FloatEvaluation implements openfeature.FeatureProvider. Octopus only supports boolean flags, so it always returns the default.

func (*FeatureProvider) Hooks

func (p *FeatureProvider) Hooks() []openfeature.Hook

Hooks implements openfeature.FeatureProvider.

func (*FeatureProvider) Init

func (p *FeatureProvider) Init(evaluationContext openfeature.EvaluationContext) error

Init implements openfeature.StateHandler.

func (*FeatureProvider) InitWithContext

InitWithContext implements openfeature.ContextAwareStateHandler. It fetches the feature flags, stopping early if ctx is done, and then checks for changes every CacheDuration until shutdown. A failed fetch isn't an error: the provider is still ready, and every evaluation returns the default with FLAG_NOT_FOUND until a later check succeeds. Calling it again while the provider is running waits for the first fetch and starts nothing new. After shutdown it returns an error, because a provider can't be initialized again.

func (*FeatureProvider) IntEvaluation

IntEvaluation implements openfeature.FeatureProvider. Octopus only supports boolean flags, so it always returns the default.

func (*FeatureProvider) Metadata

func (p *FeatureProvider) Metadata() openfeature.Metadata

Metadata implements openfeature.FeatureProvider.

func (*FeatureProvider) ObjectEvaluation

ObjectEvaluation implements openfeature.FeatureProvider. Octopus only supports boolean flags, so it always returns the default.

func (*FeatureProvider) Shutdown

func (p *FeatureProvider) Shutdown()

Shutdown implements openfeature.StateHandler.

func (*FeatureProvider) ShutdownWithContext

func (p *FeatureProvider) ShutdownWithContext(ctx context.Context) error

ShutdownWithContext implements openfeature.ContextAwareStateHandler. It stops checking for changes and cancels any request in flight, even if ctx is already done, then waits for that to finish, returning ctx's error if ctx ends first. Evaluations keep using the last feature flags fetched. It can be called more than once, and the provider can't be initialized again afterwards.

func (*FeatureProvider) StringEvaluation

StringEvaluation implements openfeature.FeatureProvider. Octopus only supports boolean flags, so it always returns the default.

type ProductMetadata

type ProductMetadata struct {
	// contains filtered or unexported fields
}

ProductMetadata describes the product using the provider. The feature flags service receives it with each request, for telemetry.

func NewProductMetadata

func NewProductMetadata(name string) (ProductMetadata, error)

NewProductMetadata returns metadata with the product's name only. Characters that aren't valid in an HTTP token are removed from name, and an error is returned if none remain.

func NewProductMetadataWithVersion

func NewProductMetadataWithVersion(name, version string) (ProductMetadata, error)

NewProductMetadataWithVersion returns metadata with the product's name and version. Characters that aren't valid in an HTTP token are removed from both, and an error is returned if none remain in either.

func (ProductMetadata) Name

func (m ProductMetadata) Name() string

Name returns the product name.

func (ProductMetadata) Version

func (m ProductMetadata) Version() string

Version returns the product version, or "" if none was given.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL