Skip to content

Add Go (Golang) language support to func init via the Native worker runtime#4854

Open
harshivcodes wants to merge 5 commits intofeature/native-lang-supportfrom
hakkaraj/func-init-native
Open

Add Go (Golang) language support to func init via the Native worker runtime#4854
harshivcodes wants to merge 5 commits intofeature/native-lang-supportfrom
hakkaraj/func-init-native

Conversation

@harshivcodes
Copy link
Copy Markdown

@harshivcodes harshivcodes commented Apr 14, 2026

This PR adds Go language support to the func init command in Azure Functions Core Tools. Go is supported under the Native worker runtime, which hosts language-native binaries directly. When a user runs func init --worker-runtime native, the CLI scaffolds a complete Go project with module initialization, dependency resolution, and a starter main.go.

Core runtime registration

  • Added WorkerRuntime.Native enum value with "go" and "golang" as aliases
  • --worker-runtime native, --worker-runtime go, and --worker-runtime golang all resolve to Native
  • When go or golang is used, a warning is printed clarifying that Golang runs under the native runtime
  • Added Constants.Languages.Golang and wired up default language/programming model mappings
  • Native appears in the interactive runtime selection picker

Go project scaffolding (GoHelpers.cs)

  • Detects installed Go version (minimum 1.24 required)
  • Runs go mod init, go get github.com/azure/azure-functions-golang-worker, and go mod tidy
  • --skip-go-mod-tidy flag to skip the tidy step (useful for CI or when the worker module is unreachable)

Static resources

  • Embedded main.go template (minimal package main + empty main())
  • Reuses existing .funcignore template
  • New entry in StaticResources.props and StaticResources.cs

InitAction integration

  • InitLanguageSpecificArtifacts handles WorkerRuntime.Native: calls GoHelpers.SetupProject, writes main.go and .funcignore
  • Docker flag emits a warning: "Docker support for the native worker runtime is not yet available"
  • Language selection wizard surfaces for Native runtime

Testing

  • 27 unit tests passing (GoHelperTests + InitActionGoTests)
  • 4 E2E test cases defined (NativeGoInitTests)
  • Manual validation of 8 scenarios: --worker-runtime native/go/golang, --skip-go-mod-tidy, named subfolder, --force in non-empty dir, --docker warning, and interactive picker
Test Scenario Result
1 --worker-runtime native All files created; FUNCTIONS_WORKER_RUNTIME: "native" set; go.mod + go.sum present
2 --worker-runtime go Same output — alias works correctly
3 --worker-runtime golang Same output — alias works correctly
4 --skip-go-mod-tidy Shows “Skipped” message; go.sum still exists (from go get)
5 Named subfolder test-go-5 Created subfolder and initialized inside it
6 --force in non-empty directory dummy.txt preserved alongside all new files
7 --docker Docker warning emitted: “Docker support for the native worker runtime is not yet available. Skipping Dockerfile creation.” No Dockerfile created
8 Interactive (no runtime flag) Picker shows Native as option 7 in the list

Output from local testing
test-results.txt

@harshivcodes harshivcodes requested a review from a team as a code owner April 14, 2026 21:43
Comment thread src/Cli/func/Actions/LocalActions/InitAction/InitAction.cs Outdated
Comment thread src/Cli/func/Helpers/WorkerRuntimeLanguageHelper.cs Outdated
Comment thread src/Cli/func/Actions/LocalActions/InitAction/InitAction.cs Outdated
Comment thread src/Cli/func/StaticResources/main.go Outdated
Comment thread src/Cli/func/Helpers/GoHelpers.cs Outdated
Comment thread src/Cli/func/Helpers/GoHelpers.cs Outdated
Comment thread src/Cli/func/Actions/LocalActions/InitAction/InitNativeSubcommandAction.cs Outdated
Comment thread src/Cli/func/Actions/LocalActions/InitAction/InitNativeSubcommandAction.cs Outdated
Comment thread src/Cli/func/Common/Constants.cs Outdated
Comment thread src/Cli/func/Helpers/GoHelpers.cs
Comment thread src/Cli/func/Actions/LocalActions/InitAction/InitAction.cs Outdated
Comment thread test/Cli/Func.E2ETests/Commands/FuncInit/NativeGoInitTests.cs
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.

3 participants