Answer the question
In order to leave comments, you need to log in
How to properly import local packages?
Hello guys, I got a question about splitting the project into folders, a regular server, I want to separate the models and everything else. In general, I had a question about importing a local package.
Like I used to do and it worked.
app
- package
-- package.go
- main.go
in main just did this and everything worked... Of course there was a nuance with a recursive package call, but it's true... But it doesn't work with the new version.
package main
import (
"./package"
)
func main() {
package.Print("Hello world!")
}
Answer the question
In order to leave comments, you need to log in
After sitting around experimenting, I answered my own question, here is a link to an example of the application structure , and yes, it’s really convenient ... the main point is to use modules and that’s all ... fall off and have to bother with something else ...
If you write a project for yourself, then it is not necessary to call it to github. You can name your project, for example "project" when initializing (go mod init) or rename it to go.mod. Then you will need to contact "project / package name". It makes sense to link to github if you are making a package for others and will place it on third-party services, then full links will help to avoid losing packages. And as Alexander Pavlyuk wrote above, in order not to lose the used third-party packages, you need to use go mod vendor.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question