GO Feature Flag integration
Feature flags lets you modify system behavior without changing code. Deploy every day, release when you are ready. Reduce risk by releasing your features progressively.
- GO Feature Flag believes in simplicity and offers a simple and lightweight solution to use feature flags.
- Target individual segments, users, and development environments, use advanced rollout functionality.
- 100% Opensource, no vendor locking, supports your favorite languages and is pushing for standardisation with the support of OpenFeature.
Hosting integration
Section titled “Hosting integration”To get started with the Aspire GO Feature Flag hosting integration, install the CommunityToolkit.Aspire.Hosting.GoFeatureFlag NuGet package in the app host project.
aspire add communitytoolkit-gofeatureflagThe Aspire CLI is interactive, be sure to select the appropriate search result when prompted:
Select an integration to add:
> communitytoolkit-gofeatureflag (CommunityToolkit.Aspire.Hosting.GoFeatureFlag)> Other results listed as selectable options...#:package CommunityToolkit.Aspire.Hosting.GoFeatureFlag@*<PackageReference Include="CommunityToolkit.Aspire.Hosting.GoFeatureFlag" Version="*" />Add goff server resource
Section titled “Add goff server resource”In your app host project, call AddGoFeatureFlag on the builder instance to add a goff container resource:
var builder = DistributedApplication.CreateBuilder(args);
var goff = builder.AddGoFeatureFlag("goff") .WithGoffBindMount("./goff");
builder.AddProject<Projects.ExampleProject>() .WithReference(goff);
// After adding all resources, run the app...When Aspire adds a container image to the app host, as shown in the preceding example with the docker.io/gofeatureflag/go-feature-flag image, it creates a new goff server instance on your local machine. A reference to your goff server (the goff variable) is added to the ExampleProject.
Flag configuration format
Section titled “Flag configuration format”goff uses either the YAML, JSON or TOML format to configure feature flags. Here is a simple example for you to get started:
display-banner: variations: enabled: true disabled: false defaultRule: variation: enabledYou can learn more on how to create flags here: Create flags with goff.
Flag configuration
Section titled “Flag configuration”In the previous section, we created flags via a configuration file. We now need another file to configure the Relay Proxy that will load your flags from the file system. Here is what you need to ingest the previous created file:
retrievers: - kind: file path: /goff/flags.yamlConfigure logging
Section titled “Configure logging”To configure debug logging for the goff container resource, call the WithLogLevel method:
var builder = DistributedApplication.CreateBuilder(args);
var goff = builder.AddGoFeatureFlag("goff") .WithGoffBindMount("./goff"); .WithLogLevel(Microsoft.Extensions.Logging.LogLevel.Debug);
builder.AddProject<Projects.ExampleProject>() .WithReference(goff);
// After adding all resources, run the app...The WithLogLevel method enables debug logging in the goff container, which provides verbose output for troubleshooting flag evaluation issues. Currently, only Debug, Information, Warning and Error log levels are supported.
Customize ports
Section titled “Customize ports”To customize the port used by the goff container resource, provide the port parameter to the AddGoFeatureFlag method:
var builder = DistributedApplication.CreateBuilder(args);
var goff = builder.AddGoFeatureFlag(name: "goff", port: 1031) .WithGoffBindMount("./goff");
builder.AddProject<Projects.ExampleProject>() .WithReference(goff);
// After adding all resources, run the app...The port parameter specifies the host port for the goff HTTP endpoint. If this parameter is not provided, a random port is assigned.
Health checks
Section titled “Health checks”The goff hosting integration automatically adds a health check for the goff server resource. The health check verifies that the goff server is running and that a connection can be established to it.
The hosting integration uses the goff /health endpoint to perform health checks.
Client integration
Section titled “Client integration”To get started with the Aspire goff 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 GO Feature Flag client
Section titled “Add GO Feature Flag client”In the Program.cs file of your client-consuming project, call the AddGoFeatureFlagClient extension method to register a GoFeatureFlagProvider for use via the dependency injection container. The method takes a connection name parameter.
builder.AddGoFeatureFlagClient(connectionName: "goff");You can then retrieve the GoFeatureFlagProvider instance using dependency injection:
public class ExampleService(GoFeatureFlagProvider provider){ // Use provider...}Add keyed GO Feature Flag client
Section titled “Add keyed GO Feature Flag client”There might be situations where you want to register multiple GoFeatureFlagProvider instances with different connection names. To register keyed goff clients, call the AddKeyedGoFeatureFlagClient method:
builder.AddKeyedGoFeatureFlagClient(name: "technical");builder.AddKeyedGoFeatureFlagClient(name: "business");Then you can retrieve the GoFeatureFlagProvider instances using dependency injection:
public class ExampleService( [FromKeyedServices("technical")] GoFeatureFlagProvider technicalProvider, [FromKeyedServices("business")] GoFeatureFlagProvider businessProvider){ // Use providers...}Client integration health checks
Section titled “Client integration health checks”The Aspire goff integration uses the configured client to perform a health check.