My goal is to create a repository with an examples folder that contains a go.mod file. This is because the example may require a library that the actual package does not need.
What I've did:
- I did
$ go work init,$ go work use ./,$ go work use ./examples. - I pushed it to the https://github.com/kidfrom/learn-golang-multiple-modules
- I created a
testproject, and did$ go get https://github.com/kidfrom/learn-golang-multiple-modulesand$ go get https://github.com/kidfrom/learn-golang-multiple-modules/examples - I ran it with
$ go run main.go
The problem is that I can't import /examples folder. It throws error
main.go:4:2: import "github.com/kidfrom/learn-golang-multiple-modules/examples" is a program, not an importable package
main.go
package main
import (
examples "github.com/kidfrom/learn-golang-multiple-modules/examples"
"github.com/kidfrom/learn-golang-multiple-modules/hello"
)
func main() {
hello.Hello()
examples.HelloWorld()
}