Redigera

Dela via


.NET Aspire Go hosting

Includes: Hosting integration not Client integration

Note

This integration is part of the .NET Aspire Community Toolkit and isn't officially supported by the .NET Aspire team.

In this article, you learn how to use the .NET Aspire Go hosting integration to host Go applications.

Hosting integration

To get started with the .NET Aspire Go hosting integration, install the 📦 CommunityToolkit.Aspire.Hosting.Go NuGet package in the AppHost project.

dotnet add package CommunityToolkit.Aspire.Hosting.Golang

For more information, see dotnet add package or Manage package dependencies in .NET applications.

Example usage

In the Program.cs file of your app host project, call the AddGolangApp method to add a Go application to the builder.

var golang = builder.AddGolangApp("golang", "../gin-api")
    .WithHttpEndpoint(env: "PORT");

The PORT environment variable is used to determine the port the Go application should listen on. By default, this port is randomly assigned by .NET Aspire. The name of the environment variable can be changed by passing a different value to the WithHttpEndpoint method.

The Go application can be added as a reference to other resources in the AppHost project.

See also