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

Copilot AI commented Dec 4, 2025

Copy link
Copy Markdown
Contributor
  • 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

tommasodotNET commented Dec 4, 2025

Copy link
Copy Markdown
Contributor

@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

@tommasodotNET tommasodotNET left a comment

Copy link
Copy Markdown
Contributor

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>

Copilot AI commented Jan 15, 2026

Copy link
Copy Markdown
Contributor Author

@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.

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