Skip to content

Add WithGoModTidy and WithGoModDownload for Golang integration#1031

Merged
aaronpowell merged 10 commits into
mainfrom
copilot/add-go-mod-tidy-download
Jan 16, 2026
Merged

Add WithGoModTidy and WithGoModDownload for Golang integration#1031
aaronpowell merged 10 commits into
mainfrom
copilot/add-go-mod-tidy-download

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 4, 2025

  • Add GoModInstallerResource class (similar to BunInstallerResource)
  • Add WithGoModTidy() extension method to run go mod tidy before app starts
  • Add WithGoModDownload() extension method to run go mod download before app starts
  • Add unit tests for the new extension methods (11 tests total)
  • Update README with documentation for new features
  • Add install parameter (default true) to control installer execution
  • Change condition from !IsPublishMode to IsRunMode per review feedback
  • Always create installer resource in run mode following JavaScript hosting pattern
  • Fix obsolete API calls (GetArgumentValuesAsync → GetArgumentListAsync)
  • Add WaitAnnotation assertions to verify installer completion wait
  • Remove unused variable assignments
  • Build and test verification complete

Summary

This PR adds support for running go mod tidy or go mod download before a Golang application starts in the Aspire Golang integration, following the JavaScript hosting pattern.

Changes Made

New Files

  • src/CommunityToolkit.Aspire.Hosting.Golang/GoModInstallerResource.cs - New resource type for the Go module installer

Modified Files

  • src/CommunityToolkit.Aspire.Hosting.Golang/GolangAppHostingExtension.cs - Added WithGoModTidy() and WithGoModDownload() extension methods with install parameter
  • src/CommunityToolkit.Aspire.Hosting.Golang/README.md - Added documentation for the new dependency management features
  • tests/CommunityToolkit.Aspire.Hosting.Golang.Tests/ResourceCreationTests.cs - Added 11 tests for the new methods

Key Behavior

The implementation follows the JavaScript hosting pattern:

  • In run mode: Installer resource is always created and visible in the Aspire dashboard
  • When install: true (default): The Go app waits for installer completion before starting (verified by WaitAnnotation)
  • When install: false: Installer is created with WithExplicitStart() - visible in dashboard but requires manual start
  • In publish mode: No installer created (Dockerfile handles dependencies)

Usage

// Using go mod tidy (default: install = true)
var golang = builder.AddGolangApp("golang", "../gin-api")
    .WithGoModTidy()
    .WithHttpEndpoint(env: "PORT");

// Installer created but requires explicit start
var golang = builder.AddGolangApp("golang", "../gin-api")
    .WithGoModTidy(install: false)
    .WithHttpEndpoint(env: "PORT");

// Using go mod download
var golang = builder.AddGolangApp("golang", "../gin-api")
    .WithGoModDownload()
    .WithHttpEndpoint(env: "PORT");

Review Feedback Addressed

  • ✅ Changed condition from !IsPublishMode to IsRunMode (comment #2693376853)
  • ✅ Added install parameter with default true (comment #3664371891)
  • ✅ Always create installer resource with decoration pattern (comment #2693423128)
  • ✅ Use WithExplicitStart() when install: false per JavaScript hosting pattern
  • ✅ Replaced obsolete GetArgumentValuesAsync() with GetArgumentListAsync() (comment #2693542533)
  • ✅ Added WaitAnnotation assertions to verify installer completion wait (comments #2693542448, #2693542473)
  • ✅ Removed unused golangResource variable assignments (comments #2693542562, #2693542631, #2693542648)
Original prompt

This section details on the original issue you should resolve

<issue_title>go mod tidy/go download</issue_title>
<issue_description>### Related to an existing integration?

Yes

Existing integration

Golang

Overview

We could add go mod tidy/go downlaod to our golang integration. @davidfowl suggested a possible implementation here: https://github.com/davidfowl/aspire-13-samples/blob/731a43a848706cf0bbcece1506122e5b6c19f2d8/golang-api/apphost.cs#L53-L61

Usage example

The api is internal to the golang resource.

Breaking change?

No

Alternatives

Manually run by user.

Additional context

No response

Help us help you

Yes, I'd like to be assigned to work on this item</issue_description>

Comments on the Issue (you are @copilot in this section)

Custom agent used: Hosting Integration Creator
This agent helps users create new hosting integration in Aspire by scaffolding the correct projects and files based on user input.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Dec 4, 2025
…integration

Co-authored-by: aaronpowell <434140+aaronpowell@users.noreply.github.com>
Copilot AI changed the title [WIP] Add go mod tidy and go download to golang integration Add WithGoModTidy and WithGoModDownload for Golang integration Dec 4, 2025
Copilot AI requested a review from aaronpowell December 4, 2025 05:40
@davidfowl
Copy link
Copy Markdown
Contributor

We use the same installer resource and swap out the command. See npm and python. We've also made some changes to how it works with respect to what install: true means

@tommasodotNET
Copy link
Copy Markdown
Contributor

tommasodotNET commented Dec 4, 2025

@aaronpowell
Copy link
Copy Markdown
Member

oh wait, IIRC there was a new installer base stack coming wasn't there @davidfowl ?

@github-actions github-actions Bot added the Stale label Dec 10, 2025
@aaronpowell aaronpowell added this to the 13.1 milestone Dec 11, 2025
@github-actions github-actions Bot added Stale and removed Stale labels Dec 11, 2025
@github-actions github-actions Bot closed this Dec 19, 2025
@tommasodotNET tommasodotNET reopened this Dec 19, 2025
@github-actions github-actions Bot added Stale and removed Stale labels Dec 20, 2025
@github-actions github-actions Bot closed this Dec 28, 2025
@tommasodotNET tommasodotNET reopened this Jan 15, 2026
Copy link
Copy Markdown
Contributor

@tommasodotNET tommasodotNET left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot on top of my comment, we also want to add the install flag on the mod extension:When true (default), automatically installs packages before the application starts. When false, only sets the package manager annotation without creating an installer resource.

see here an implementation example
https://raw.githubusercontent.com/dotnet/aspire/refs/heads/main/src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs

Comment thread src/CommunityToolkit.Aspire.Hosting.Golang/GolangAppHostingExtension.cs Outdated
…of IsPublishMode

Co-authored-by: tommasodotNET <12819039+tommasodotNET@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 15, 2026

@copilot on top of my comment, we also want to add the install flag on the mod extension:When true (default), automatically installs packages before the application starts. Whe...

Added the install parameter with default true to both methods in commit a394e28. When install: false, the methods do not create an installer resource. The behavior now matches the JavaScript hosting pattern you referenced.

tommasodotNET and others added 3 commits January 15, 2026 10:12
…ationTests.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ationTests.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ationTests.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…n assertions, remove unused variables

Co-authored-by: tommasodotNET <12819039+tommasodotNET@users.noreply.github.com>
@aaronpowell aaronpowell removed the Stale label Jan 16, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Code Coverage

Package Line Rate Branch Rate Complexity Health
CommunityToolkit.Aspire.GoFeatureFlag 100% 97% 74
CommunityToolkit.Aspire.Hosting.ActiveMQ 78% 40% 108
CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit 1% 0% 14
CommunityToolkit.Aspire.Hosting.Adminer 74% 50% 20
CommunityToolkit.Aspire.Hosting.Azure.Dapr 29% 7% 124
CommunityToolkit.Aspire.Hosting.Azure.Dapr.Redis 62% 38% 80
CommunityToolkit.Aspire.Hosting.Azure.DataApiBuilder 100% 100% 22
CommunityToolkit.Aspire.Hosting.Bun 96% 83% 28
CommunityToolkit.Aspire.Hosting.Dapr 60% 37% 856
CommunityToolkit.Aspire.Hosting.DbGate 94% 50% 18
CommunityToolkit.Aspire.Hosting.Deno 98% 85% 44
CommunityToolkit.Aspire.Hosting.Elasticsearch.Extensions 99% 93% 46
CommunityToolkit.Aspire.Hosting.Flagd 79% 100% 32
CommunityToolkit.Aspire.Hosting.Flyway 94% 100% 8
CommunityToolkit.Aspire.Hosting.GoFeatureFlag 88% 73% 36
CommunityToolkit.Aspire.Hosting.Golang 61% 50% 114
CommunityToolkit.Aspire.Hosting.Java 70% 75% 130
CommunityToolkit.Aspire.Hosting.JavaScript.Extensions 97% 85% 200
CommunityToolkit.Aspire.Hosting.k6 58% 12% 20
CommunityToolkit.Aspire.Hosting.Keycloak.Extensions 100% 100% 22
CommunityToolkit.Aspire.Hosting.KurrentDB 71% 75% 34
CommunityToolkit.Aspire.Hosting.LavinMQ 74% 50% 26
CommunityToolkit.Aspire.Hosting.LavinMQ.MassTransit 1% 0% 14
CommunityToolkit.Aspire.Hosting.MailPit 85% 50% 22
CommunityToolkit.Aspire.Hosting.McpInspector 78% 45% 210
CommunityToolkit.Aspire.Hosting.Meilisearch 71% 57% 58
CommunityToolkit.Aspire.Hosting.Minio 88% 75% 56
CommunityToolkit.Aspire.Hosting.MongoDB.Extensions 95% 90% 20
CommunityToolkit.Aspire.Hosting.MySql.Extensions 98% 92% 62
CommunityToolkit.Aspire.Hosting.Ngrok 52% 35% 82
CommunityToolkit.Aspire.Hosting.Ollama 65% 69% 260
CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector 78% 61% 77
CommunityToolkit.Aspire.Hosting.PapercutSmtp 81% 50% 18
CommunityToolkit.Aspire.Hosting.PostgreSQL.Extensions 98% 90% 74
CommunityToolkit.Aspire.Hosting.Python.Extensions 45% 29% 100
CommunityToolkit.Aspire.Hosting.RavenDB 56% 45% 184
CommunityToolkit.Aspire.Hosting.Redis.Extensions 100% 71% 28
CommunityToolkit.Aspire.Hosting.Rust 94% 83% 16
CommunityToolkit.Aspire.Hosting.Sftp 59% 32% 40
CommunityToolkit.Aspire.Hosting.Solr 72% 100% 22
CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects 51% 48% 192
CommunityToolkit.Aspire.Hosting.Sqlite 89% 89% 52
CommunityToolkit.Aspire.Hosting.SqlServer.Extensions 98% 90% 62
CommunityToolkit.Aspire.Hosting.Stripe 51% 30% 82
CommunityToolkit.Aspire.Hosting.SurrealDb 55% 40% 256
CommunityToolkit.Aspire.KurrentDB 94% 92% 54
CommunityToolkit.Aspire.MassTransit.RabbitMQ 100% 100% 30
CommunityToolkit.Aspire.Meilisearch 97% 92% 68
CommunityToolkit.Aspire.Microsoft.Data.Sqlite 89% 85% 52
CommunityToolkit.Aspire.Microsoft.EntityFrameworkCore.Sqlite 61% 58% 114
CommunityToolkit.Aspire.Minio.Client 90% 85% 112
CommunityToolkit.Aspire.OllamaSharp 78% 71% 134
CommunityToolkit.Aspire.RavenDB.Client 60% 53% 237
CommunityToolkit.Aspire.Sftp 86% 78% 86
CommunityToolkit.Aspire.SurrealDb 79% 63% 78
Summary 68% (7890 / 11644) 56% (2166 / 3902) 5008

Minimum allowed line rate is 60%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

go mod tidy/go download

5 participants