why import is a program, not an importable package (compile)?

Viewed 139

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:

  1. I did $ go work init, $ go work use ./, $ go work use ./examples.
  2. I pushed it to the https://github.com/kidfrom/learn-golang-multiple-modules
  3. I created a test project, and did $ go get https://github.com/kidfrom/learn-golang-multiple-modules and $ go get https://github.com/kidfrom/learn-golang-multiple-modules/examples
  4. 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()
}
0 Answers
Related