GOPATH Package Import Issue
You're encountering an issue importing local packages within your GOPATH but not in your home directory. Your project structure, as you've described, appears to be correct.
Relative Import Paths
In Go, relative import paths are discouraged. They are primarily meant for experimentation and are not fully supported by the go build and go install commands. For your project to work seamlessly with Go tools, it's recommended to avoid using relative imports.
GOPATH Structure
GOPATH is an environment variable that specifies directories where Go looks for packages. The default GOPATH is set to your home directory ($HOME/go). In your case, when the project is located at $GOPATH/src/project, you can't import local packages because the Go tools are not able to locate them correctly.
Recommendations
To resolve this issue, consider the following:
Use Absolute Import Paths: Instead of using relative import paths, use the absolute paths of your local packages. In your case, the import statement for your models package should be:
import "projpath/models"
Replace projpath with the actual path to the project directory.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3