From ecdc3f5e810dee97c7b103eefc9b3fa158fafe57 Mon Sep 17 00:00:00 2001 From: Lillian Hwang-Geddes Date: Wed, 29 Apr 2026 13:50:13 -0400 Subject: [PATCH 1/2] Run go mod tidy and bump Go version to 1.25 in generated module template After generating a Go module, automatically run `go mod tidy` in the new module directory to resolve dependencies. Also updates the go.mod template from go 1.23 to 1.25. Co-Authored-By: Claude Sonnet 4.6 --- cli/module_generate.go | 7 +++++++ cli/module_generate/_templates/go/tmpl-go.mod | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cli/module_generate.go b/cli/module_generate.go index 52c5ac90b89..34a965fb64e 100644 --- a/cli/module_generate.go +++ b/cli/module_generate.go @@ -245,6 +245,13 @@ func (c *viamClient) generateModuleAction(ctx context.Context, cmd *cli.Command, "To access your module in app, make sure to add \"tcp_mode\": true to the module config json\n"+ "and set your local module's executable path to run.bat") } + if newModule.Language == golang { + tidyCmd := exec.Command("go", "mod", "tidy") + tidyCmd.Dir = newModule.ModuleName + if err := tidyCmd.Run(); err != nil { + return fmt.Errorf("failed to run go mod tidy: %w", err) + } + } return nil } diff --git a/cli/module_generate/_templates/go/tmpl-go.mod b/cli/module_generate/_templates/go/tmpl-go.mod index 4256aaa08eb..f06a3844dcd 100644 --- a/cli/module_generate/_templates/go/tmpl-go.mod +++ b/cli/module_generate/_templates/go/tmpl-go.mod @@ -1,3 +1,3 @@ module {{.ModuleLowercase}} -go 1.23 +go 1.25 From c894165be1dd78e19e162fe9d2fdc921f6fc9389 Mon Sep 17 00:00:00 2001 From: Lillian Hwang-Geddes Date: Fri, 1 May 2026 17:24:50 -0400 Subject: [PATCH 2/2] move go mod tidy command to generateGolandStubs --- cli/module_generate.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cli/module_generate.go b/cli/module_generate.go index 34a965fb64e..79f4c19195d 100644 --- a/cli/module_generate.go +++ b/cli/module_generate.go @@ -245,13 +245,6 @@ func (c *viamClient) generateModuleAction(ctx context.Context, cmd *cli.Command, "To access your module in app, make sure to add \"tcp_mode\": true to the module config json\n"+ "and set your local module's executable path to run.bat") } - if newModule.Language == golang { - tidyCmd := exec.Command("go", "mod", "tidy") - tidyCmd.Dir = newModule.ModuleName - if err := tidyCmd.Run(); err != nil { - return fmt.Errorf("failed to run go mod tidy: %w", err) - } - } return nil } @@ -794,6 +787,15 @@ func generateGolangStubs(module modulegen.ModuleInputs) error { return errors.Wrap(err, "cannot generate go stubs -- unable to sort imports") } + // run go mod tidy + if module.Language == golang { + tidyCmd := exec.Command("go", "mod", "tidy") + tidyCmd.Dir = module.ModuleName + if err := tidyCmd.Run(); err != nil { + return fmt.Errorf("failed to run go mod tidy: %w", err) + } + } + return nil }