Golang modules: Difference between revisions
From wikinotes
No edit summary |
No edit summary |
||
Line 28: | Line 28: | ||
</blockquote><!-- Vendoring --> | </blockquote><!-- Vendoring --> | ||
= Publishing Modules = | |||
<blockquote> | |||
== Public Modules == | |||
<blockquote> | |||
All published packages are public by default.<br> | |||
You can <code>retract</code> package versions if you discovered a mistake.<br> | |||
Official package publishing instructions [https://go.dev/doc/modules/publishing here]. | |||
Release Preparation | |||
<syntaxhighlight lang="bash"> | |||
go mod tidy | |||
go test | |||
git tag v0.0.1 | |||
git push origin v0.0.1 | |||
</syntaxhighlight> | |||
Publishing your package | |||
<syntaxhighlight lang="bash"> | |||
# 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.0 | |||
</syntaxhighlight> | |||
</blockquote><!-- Public Packages --> | |||
== Private Modules == | |||
<blockquote> | |||
Go executables are installed/built from src.<br> | |||
You'll need to add your package to <code>$GOPRIVATE</code> envvar to stop it from being indexed.<br> | |||
While unset <code>$GONOPROXY</code> and <code>$GONOSUMDB</code>, will fall back on <code>$GOPRIVATE</code>.<br> | |||
Otherwise you'll want to set these to prevent your packages from getting added to the index. | |||
</blockquote><!-- Private Packages --> | |||
</blockquote><!-- Creating Packages --> |
Revision as of 13:55, 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.
Modules
Creating/Requiring Modules
See go.mod file.
Module Requirements
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.mod
Vendoring
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.