I tried to setup a new Go project using subdirectories (using internals).
Directory structure look like this:
Root directory: /Users/xyz/code/ppPrinter
.
├── go.mod
├── internal
│ ├── backends
│ │ └── bar.go
│ └── commands
└── main.go
Go mod:
module bitbucket.org/foo/ppprint.git
go 1.22.5
main.go:
package main
import (
"fmt"
be "bitbucket.org/foo/ppPrint.git/internal/backends"
)
// Hello returns a greeting for the named person.
func main() {
// Return a greeting that embeds the name in a message.
foo := be.Hello("Gladys")
message := fmt.Sprintf("Hi, %v. Welcome!", name)
return message
}
bar.go:
package backends
import "fmt"
// Hello returns a greeting for the named person.
func Hello(name string) string {
// Return a greeting that embeds the name in a message.
message := fmt.Sprintf("Hi, %v. Welcome!", name)
return message
}
On my system there an no GO* env variables set by default: env | grep GO
returns nothing.
Running main.go:
cd $HOME/code/ppPrinter/ && go run main.go
main.go:6:2: no required module provides package bitbucket.org/foo/ppPrint.git/internal/backends; to add it:
go get bitbucket.org/foo/ppPrint.git/internal/backends
Same error when setting GOPATH to $HOME/code/ppPrinter
.
What am I missing (I just want to be able to structure my local project in subdirectories) ?