Plus, you don't need to do a "go mod init" in each subdirectory. The top-level directory names the module and the package within it; you can refer to packages in subdirectories using this module name with the subdirectory appended.
A typical layout would look like this: (top level) go mod init example.com/foo [whatever.go] package main import "example.com/foo/bar" import "example.com/foo/baz" .... (subdirectory "bar") [whatever.go] package bar import "example.com/foo/baz" // if required ... (subdirectory "baz") [whatever.go] package baz import "example.com/foo/bar" // if required ... You can test all this in the playground: https://go.dev/play/p/-PR3oartg0t On Friday, 9 December 2022 at 05:39:12 UTC Volker Dobler wrote: > You cannot have multiple packages (in your case main and goprorename) > in one folder. This has nothing to do with modules. You must but these > three files into two different folders based on their package declaration. > > You might want to work through https://go.dev/doc/code > > V. > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/88465fba-8cfa-406c-84d8-1f7b4ccc5212n%40googlegroups.com.