Golang modules: Difference between revisions
No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
You define your project requirements in at the module level,<br> | You define your project requirements in at the module level,<br> | ||
and you can publish module-versions to the go package index. | and you can publish module-versions to the go package index. | ||
= Documentation = | |||
<blockquote> | |||
{| class="wikitable" | |||
|- | |||
| private modules || https://go.dev/ref/mod#private-modules | |||
|- | |||
| module proxies || https://go.dev/ref/mod#module-proxy | |||
|- | |||
| module cache || https://go.dev/ref/mod#module-cache | |||
|- | |||
|} | |||
</blockquote><!-- Documentation --> | |||
= Locations = | |||
<blockquote> | |||
{| class="wikitable" | |||
|- | |||
| go module index || https://index.golang.org/index | |||
|- | |||
| go checksum index || https://sum.golang.org/ | |||
|- | |||
| <code>~/go/bin</code> || default <code>$GOBIN</code> path, where go executables are installed | |||
|- | |||
|} | |||
</blockquote><!-- Locations --> | |||
= Go.mod file = | = Go.mod file = |
Revision as of 14:01, 19 June 2022
Go modules are a collection of packages that are intended to be released together.
You define your project requirements in at the module level,
and you can publish module-versions to the go package index.
Documentation
private modules https://go.dev/ref/mod#private-modules module proxies https://go.dev/ref/mod#module-proxy module cache https://go.dev/ref/mod#module-cache
Locations
go module index https://index.golang.org/index go checksum index https://sum.golang.org/ ~/go/bin
default $GOBIN
path, where go executables are installed
Go.mod file
The go.mod file stores metadata about your project, and it's requirements.
There are several tools to help manage it, but this is the source of truth.
Module Requirements
Tools
See also go.mod file .
go mod graph # show requirements tree go mod tidy # ensure go.mod matches src go mod vendor # go get ... # add requirement to go.modVendoring
Publishing Modules
Public Modules
All published packages are public by default.
You canretract
package versions if you discovered a mistake.
Official package publishing instructions here.Release Preparation
go mod tidy go test git tag v0.0.1 git push origin v0.0.1Publishing your package
# adds your package to the index go list # add specific module-version to a specific-index GOPROXY=proxy.golang.org \ go list \ -m example.com/mymodule@v0.1.0Private Modules
Go executables are installed/built from src.
You'll need to add your package to$GOPRIVATE
envvar to stop it from being indexed.
While unset$GONOPROXY
and$GONOSUMDB
, will fall back on$GOPRIVATE
.
Otherwise you'll want to set these to prevent your packages from getting added to the index.