I've been unsuccessful in importing a package from a local project (a Go module). Here is a brief of what I'm trying:
I created a Go module package like so:
$ cd
$ mkdir mymodule
$ cd mymodule
$ go mod init github.com/Company/mymodule
Then I added hello.go
under the mymodule
with a little function
// mymodule/hello.go
package mymodule
func sayHello() string {
return "Hello"
}
go build
was successful.
Note that the module is not pushed to github repository yet. I want to use (and perhaps test) mymodule before I push to github. So I created another package, like so:
$ cd
$ mkdir test
$ cd test
$ go mod init github.com/Company/test
Then, created a new file test.go
under the test
directory and in there I try to import mymodule
, like so:
// test/test.go
import (
"fmt"
"github.com/Company/mymodule"
)
func testMyModule() {
fmt.Println(mymodule.sayHello())
}
But go build
of test
fails with the below error. What gives?
cannot load github.com/Company/mymodule: cannot find module providing package github.com/Company/mymodule