Golang - Why can't I import local package in GOPATH/src/project but can in home directory?

前端 未结 2 1697
遇见更好的自我
遇见更好的自我 2021-01-18 21:40

I have a project, its folder structure is like following:

    /project
        models/
            Product.go
        main.go

The content o

相关标签:
2条回答
  • 2021-01-18 22:02

    Relative import paths are only allowed as a convenience, mostly for experimentation. They are not fully supported by go build and go install. If you want your package to work with the go tools, don't use relative imports. Structure your code as described in How to Write Go Code.

    0 讨论(0)
  • 2021-01-18 22:06

    As you are using "github.com/gin-gonic/gin" in your code. It is an external import. So go compiler will try to find this package in your workspace. So you need manually download those package in your go workspace or build path "go get github.com/gin-gonic/gin".

    0 讨论(0)
提交回复
热议问题