To create a module, just use:
go mod init github.com/seunome/seumodulo
This will create the go.mod
. I suppose I make a push
of that package against the github.com/seunome/seumodulo
, you can take this package from there in the future.
Note: you can have several packages within a single module, so when creating new modules you should have a good reason to do so. You don’t need to create a module for each package. Personally, I only create modules when I intend to share it, or reuse in other projects.
So, let’s assume you have the meuprojeto
who wants to use the seumodulo
: first the meuprojeto
should also be a module, ie also use:
go mod init github.com/seunome/meuprojeto
To consume the "meumodulo" created earlier, you can simply use:
go get github.com/seunome/seumodulo
This command must be executed inside the folder go.mod
, if it won’t go wrong. That way, the seumodulo
will be available for use within the meuprojeto
.
If your package is in another folder, locally stored, you can use the replace
in the go.mod
:
replace github.com/seunome/seumodulo => ../caminho/para/o/seumodulo
This way, instead of getting and using the information from the Github repository, you will use that of the specified folder. This is useful if you are working on a/Fork branch for seumodulo
.
If i repository is private, you can use something like:
set GOPROXY=https://proxy.golang.org,direct
set GOPRIVATE=github.com/seunome/*
That way, you can give the go get
in a private repository.