I have two separate Go repositories. One contains an application, another a shared library that the application would like to use. Neither are in $GOPATH.
~/projects/
├── myapplication
│ ├── go.mod
│ └── myapplication.go
└── mylibrary
├── go.mod
└── mylibrary.go
mylibrary/go.mod
module example.com/mylibrary
go 1.14
mylibrary/mylibrary.go
package mylibrary
var Message = "Hello, World!"
myapplication/go.mod
module example.com/myapplication
go 1.14
myapplication/myapplication.go
package myapplication
import (
"fmt"
"example.com/mylibrary"
)
func main() {
fmt.Println(mylibrary.Message)
}
I have no reason to believe that the above should work as the application has no way of finding out where the library is. How do I?
I have tried the following with now results.
- adding
~/projects/mylibrary
to GOPATH - running
go install
for mylibrary
Running go build
for the application gives:
myapplication $ go build
go: finding module for package example.com/mylibrary
myapplication.go:5:2: cannot find module providing package example.com/mylibrary: unrecognized import path "example.com/mylibrary": reading https://example.com/mylibrary?go-get=1: 404 Not Found
I can see that it is reaching out to example.com to find the repository (understandably). But how can I tell it to look for somewhere locally first?