If you want your module if you want to introduce the rest of the local module, you can try to replace the specified directory, and the premise of the article is that you have to go in a module, rather than a package under gopath be introduced.
Short answer me give you an example, such as now there are two projects, namely the blog and article, results are as follows:
├─article
│ article.go
│ go.mod
│
├─blog
│ go.mod
│ main.go
blog entry is applied, main location, and the article can be understood as a public library you write, which provides a function Hello (). Now, to call the Hello article in the () function in the blog.
SUMMARY go.mod article module as follows:
module article
go 1.13
article.go reads as follows:
package article
func Hello() string { return "Hello" }
go.mod blog content module is as follows:
go 1.13
require github.com/article v0.0.0-incompatible
replace github.com/article => ../article
Under replace a little here, the reason why if the github.com/article format, because go1.13 in, go module specifications path name of the first part of the domain name must meet the specifications, or it may report similar to malformed module path "article": missing dot in first path element
this error. Of course, there will be no go1.12 report this error. Advice, if it is an internal company use, can be replaced within the company domain name.
The second parameter specifies replace not obtained from a remote, but a module in the local alternative path github.com/article.
main.go reads as follows:
package main
import (
"fmt"
"github.com/article"
)
func main() { fmt.Println("Hello") fmt.Println(article.Hello()) }
At this point, do go run main.go in the blog it can successfully run.