I'm trying out Go's new modules system and am having trouble accessing local packages. The following project is in a folder on my desktop outside my gopath.
My project structure looks like:
/
- /platform
- platform.go
- main.go
- go.mod
// platform.go
package platform
import "fmt"
func Print() {
fmt.Println("Hi")
}
// main.go
package main
import "platform"
func main() {
platform.Print()
}
go build main.go tells me
cannot find module for path platform
I would strongly suggest you to use go toolchain which takes care of these issues out of the box. Visual Studio Code with vscode-go plugin is really useful.
Problem here is that Go requires relative paths with respect to your
$GOPATH/srcormodulein import statement. Depending on where you are in yourGOPATH, import path should include that as well. In this case, import statement must include go module path ingo.modGOPATH
Assume your project resides here:
Your import path should be:
VGO
Assume your go.mod file is:
Your import path should be: