Connect to GO Feature Flag
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
This page describes how consuming apps connect to a GO Feature Flag relay proxy resource that’s already modeled in your AppHost. For the AppHost API surface — adding a relay proxy resource, bind mounts, data volumes, log levels, and more — see GO Feature Flag Hosting integration.
When you reference a GO Feature Flag resource from your AppHost, Aspire injects the relay proxy endpoint into the consuming app as environment variables. Your app can either read those environment variables directly — the pattern works the same from any language — or, in C#, use the Aspire GO Feature Flag client integration for automatic dependency injection and health checks.
Connection properties
Section titled “Connection properties”Aspire exposes each property as an environment variable named [RESOURCE]_[PROPERTY]. For instance, the Uri property of a resource called goff becomes GOFF_URI.
The GO Feature Flag resource exposes the following connection properties:
| Property Name | Description |
|---|---|
Host | The hostname or IP address of the GO Feature Flag relay proxy |
Port | The port number the relay proxy is listening on |
Uri | The HTTP base URL of the relay proxy, with the format http://{Host}:{Port} |
The connection string injected into ConnectionStrings__goff uses the format Endpoint=http://{Host}:{Port}.
Example connection values:
Uri: http://localhost:1031ConnectionStrings__goff: Endpoint=http://localhost:1031Connect from your app
Section titled “Connect from your app”Pick the language your consuming app is written in. Each example assumes your AppHost adds a GO Feature Flag resource named goff and references it from the consuming app.
For C# apps, the recommended approach is the Aspire GO Feature Flag client integration. It registers a GOFeatureFlagProvider through dependency injection and adds health checks automatically. If you’d rather read environment variables directly, see the Read environment variables section at the end of this tab.
Install the client integration
Section titled “Install the client integration”Install the 📦 CommunityToolkit.Aspire.GoFeatureFlag NuGet package in the client-consuming project:
dotnet add package CommunityToolkit.Aspire.GoFeatureFlag#:package CommunityToolkit.Aspire.GoFeatureFlag@*<PackageReference Include="CommunityToolkit.Aspire.GoFeatureFlag" Version="*" />Add the GO Feature Flag client
Section titled “Add the GO Feature Flag client”In Program.cs, call AddGoFeatureFlagClient on your IHostApplicationBuilder to register a GOFeatureFlagProvider:
builder.AddGoFeatureFlagClient(connectionName: "goff");Resolve the provider through dependency injection:
using OpenFeature.Providers.GOFeatureFlag;
public class ExampleService(GOFeatureFlagProvider provider){ // Use provider to evaluate feature flags...}Add keyed GO Feature Flag clients
Section titled “Add keyed GO Feature Flag clients”To register multiple GOFeatureFlagProvider instances with different connection names, use AddKeyedGoFeatureFlagClient:
builder.AddKeyedGoFeatureFlagClient(name: "technical");builder.AddKeyedGoFeatureFlagClient(name: "business");Then resolve each instance by key:
using OpenFeature.Providers.GOFeatureFlag;
public class ExampleService( [FromKeyedServices("technical")] GOFeatureFlagProvider technicalProvider, [FromKeyedServices("business")] GOFeatureFlagProvider businessProvider){ // Use providers...}For more information, see .NET dependency injection: Keyed services.
Configuration
Section titled “Configuration”The Aspire GO Feature Flag client integration offers multiple ways to provide configuration.
Connection strings. When using a connection string from the ConnectionStrings configuration section, pass the connection name to AddGoFeatureFlagClient:
builder.AddGoFeatureFlagClient("goff");The connection string is resolved from the ConnectionStrings section. It is accepted either as a bare URL or in the Endpoint=... key-value format:
{ "ConnectionStrings": { "goff": "Endpoint=http://myserver:1031" }}Configuration providers. The client integration supports Microsoft.Extensions.Configuration. It loads GoFeatureFlagClientSettings from appsettings.json (or any other configuration source) by using the Aspire:GoFeatureFlag:Client key:
{ "Aspire": { "GoFeatureFlag": { "Client": { "Endpoint": "http://myserver:1031", "DisableHealthChecks": false, "HealthCheckTimeout": 5000 } } }}Inline delegates. Pass an Action<GoFeatureFlagClientSettings> to configure settings inline, for example to disable health checks:
builder.AddGoFeatureFlagClient( "goff", static settings => settings.DisableHealthChecks = true);Client integration health checks
Section titled “Client integration health checks”Aspire client integrations enable health checks by default. The GO Feature Flag client integration adds a health check that calls the relay proxy /health endpoint to verify it is reachable. The health check is wired into the /health HTTP endpoint of your app, where all registered health checks must pass before the app is considered ready to accept traffic.
Read environment variables in C#
Section titled “Read environment variables in C#”If you prefer not to use the Aspire client integration, you can read the Aspire-injected URI from the environment and configure the OpenFeature GOFeatureFlagProvider directly:
using OpenFeature;using OpenFeature.Providers.GOFeatureFlag;
var endpoint = Environment.GetEnvironmentVariable("GOFF_URI");
var provider = new GOFeatureFlagProvider(new GOFeatureFlagProviderOptions{ Endpoint = endpoint + "/",});
await OpenFeature.Api.Instance.SetProviderAsync(provider);
var client = OpenFeature.Api.Instance.GetClient();// Use client to evaluate feature flags...Use the OpenFeature Go SDK with the GO Feature Flag relay proxy provider:
go get github.com/open-feature/go-sdk/pkg/openfeaturego get github.com/open-feature/go-sdk-contrib/providers/go-feature-flag/v2/pkgRead the injected environment variable and connect:
package main
import ( "context" "os"
gofeatureflagProvider "github.com/open-feature/go-sdk-contrib/providers/go-feature-flag/v2/pkg" "github.com/open-feature/go-sdk/pkg/openfeature")
func main() { // Read the Aspire-injected relay proxy URI endpoint := os.Getenv("GOFF_URI") + "/"
provider, err := gofeatureflagProvider.NewProvider(gofeatureflagProvider.ProviderOptions{ Endpoint: endpoint, }) if err != nil { panic(err) }
if err := openfeature.SetProvider(provider); err != nil { panic(err) }
client := openfeature.NewClient("my-app") _ = client // Use client to evaluate feature flags...}Install the OpenFeature Python SDK and the GO Feature Flag Python provider:
pip install openfeature-sdkpip install gofeatureflag-python-providerRead the injected environment variable and connect:
import osfrom openfeature import apifrom gofeatureflag_python_provider.provider import GoFeatureFlagProviderfrom gofeatureflag_python_provider.options import GoFeatureFlagOptions
# Read the Aspire-injected relay proxy URIendpoint = os.getenv("GOFF_URI") + "/"
options = GoFeatureFlagOptions(endpoint=endpoint)provider = GoFeatureFlagProvider(options=options)
api.set_provider(provider)client = api.get_client("my-app")# Use client to evaluate feature flags...Node.js (server-side)
Section titled “Node.js (server-side)”Install the OpenFeature server SDK and the GO Feature Flag Node.js provider:
npm install @openfeature/server-sdknpm install @openfeature/go-feature-flag-providerRead the injected environment variable and connect:
import { OpenFeature } from '@openfeature/server-sdk';import { GoFeatureFlagProvider } from '@openfeature/go-feature-flag-provider';
// Read the Aspire-injected relay proxy URIconst endpoint = process.env.GOFF_URI + '/';
await OpenFeature.setProviderAndWait( new GoFeatureFlagProvider({ endpoint }));
const client = OpenFeature.getClient();// Use client to evaluate feature flags...Browser (web)
Section titled “Browser (web)”For browser-based apps, install the OpenFeature web SDK and the GO Feature Flag web provider:
npm install @openfeature/web-sdknpm install @openfeature/go-feature-flag-web-providerimport { OpenFeature } from '@openfeature/web-sdk';import { GoFeatureFlagWebProvider } from '@openfeature/go-feature-flag-web-provider';
// Read the Aspire-injected relay proxy URI (e.g. from a server-side env var// exposed to the client, or a public environment variable in your framework)const endpoint = process.env.NEXT_PUBLIC_GOFF_URI + '/';
await OpenFeature.setProviderAndWait( new GoFeatureFlagWebProvider({ endpoint }));
const client = OpenFeature.getClient();// Use client to evaluate feature flags...