Golang packaging: Difference between revisions

From wikinotes
No edit summary
Line 32: Line 32:
</blockquote><!-- Locations -->
</blockquote><!-- Locations -->


= Os Packages =
= OS Package Management =
<blockquote>
<blockquote>
== Install Executable ==
Installing Packages
<syntaxhighlight lang="bash">
# golang < 1.18
go get -u example.com/x/foo
 
# golang >= 1.18
go install example.com/x/foo@latest
</syntaxhighlight>
 
Uninstalling Packages
<syntaxhighlight lang="bash">
go clean -i example.com/x/foo
</syntaxhighlight>
</blockquote><!-- Package Management -->
 
= Project Requirements =
<blockquote>
== Module Requirements ==
<blockquote>
<blockquote>
Starting in golang-1.18, <code>go install</code> is used to install executables.
See also [[go.mod file]] .


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
go install github.com/appliedgocode/goman@latest # install latest goman executable
go mod graph      # show requirements tree
go mod tidy    # ensure go.mod matches src
go mod vendor #
go get ...    # add requirement to go.mod
</syntaxhighlight>
</syntaxhighlight>
</blockquote><!-- Install Executable -->
</blockquote><!-- Module Requirements -->


== Public Packages ==
== Vendoring ==
<blockquote>
 
</blockquote><!-- Vendoring -->
</blockquote><!-- Project Requirements -->
 
= Publishing Modules =
<blockquote>
== Public Modules ==
<blockquote>
<blockquote>
All published packages are public by default.<br>
All published packages are public by default.<br>
Line 69: Line 97:
</blockquote><!-- Public Packages -->
</blockquote><!-- Public Packages -->


== Private Packages ==
== Private Modules ==
<blockquote>
<blockquote>
Go executables are installed/built from src.<br>
Go executables are installed/built from src.<br>
Line 75: Line 103:
While unset <code>$GONOPROXY</code> and <code>$GONOSUMDB</code>, will fall back on <code>$GOPRIVATE</code>.<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.
Otherwise you'll want to set these to prevent your packages from getting added to the index.
</blockquote><!-- Private Packages -->
</blockquote><!-- Private Packages -->
</blockquote><!-- Os Packages -->
</blockquote><!-- Creating Packages -->
 
= Project Requirements =
<blockquote>
== Module Requirements ==
<blockquote>
See also [[go.mod file]] .
 
<syntaxhighlight lang="bash">
go mod graph      # show requirements tree
go mod tidy    # ensure go.mod matches src
go mod vendor  #
go get ...    # add requirement to go.mod
</syntaxhighlight>
</blockquote><!-- Module Requirements -->
 
== Vendoring ==
<blockquote>
 
</blockquote><!-- Vendoring -->
</blockquote><!-- Project Requirements -->

Revision as of 13:29, 19 June 2022

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/

Locations

~/go/bin default $GOBIN path, where go executables are installed

OS Package Management

Installing Packages

# golang < 1.18
go get -u example.com/x/foo

# golang >= 1.18
go install example.com/x/foo@latest

Uninstalling Packages

go clean -i example.com/x/foo

Project Requirements

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 can retract 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.1

Publishing 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.0

Private 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.