Answer the question
In order to leave comments, you need to log in
How to use Go modules correctly?
I do not understand how to use modules without publishing them in the version control system?
For example, I create a folder
c: / Project
in it a folder for modules
c : / Project / Modules.pack, then a
folder for the c: / Project / Modules.pack / mod1
submodule,
I do go mod init Modules.pack / mod1 in it,
then go get
everything is ok it seems to tighten up the dependencies and add from go.mod
now I want to make a module that will use mod1
c:/Project/Modules.pack/mod2
in the mod2.go file
package mod2
import (
. "Modules.pack/mod1"
)
....
Answer the question
In order to leave comments, you need to log in
If you need an example of how to use it locally, you can see an example in the go-openvz-api repository . This is the first code commit (commit), before using go modules.
Later in the commit history, I subsequently switched to go modules.
main.go
package main
import "./package1"
...
package package1
import (
"fmt"
)
...
package package1
...
go mod init example.org/user/mypackage
example.org/user/mypackage
. Everything in the subdirectories of the project, when importing, must be specified as example.org/user/mypackage/название_подпапки
(for example, example.org/user/mypackage/package1
). replace example.org/user/mypackage => ./
example.org/user/mypackage
to the true location of the repository, and delete the line replace
from go.mod, otherwise it will only look for the code locally. . "Modules.pack/mod1"
"./Modules.pack/mod1"
"example.org/user/Modules.pack/mod1"
"qqw example.org/user/Modules.pack/mod1" // а в самом коде ниже писать qqw вместо mod1
go get
use go mod tidy
. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question