Golang packaging: Difference between revisions

From wikinotes
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
= Documentation =
How to install executables,<br>
<blockquote>
manage project requirements,<br>
{| class="wikitable"
and publish your project to the go index (or create a private module).
|-
| 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 =
= Locations =
Line 16: Line 7:
{| class="wikitable"
{| class="wikitable"
|-
|-
| go module index || https://index.golang.org/index
| <code>~/go/bin</code> || default <code>$GOBIN</code> path, where go executables are installed
|-
| go checksum index || https://sum.golang.org/
|-
|-
|}
|}
</blockquote><!-- Locations -->
</blockquote><!-- Locations -->


= Locations =
<blockquote>
{| class="wikitable"
|-
| <code>~/go/bin</code> || default <code>$GOBIN</code> path, where go executables are installed
|-
|}
</blockquote><!-- Locations -->


= OS Package Management =
= OS Package Management =
Line 48: Line 29:
rm ${GOBIN:=~/go/bin}/tool-to-delete
rm ${GOBIN:=~/go/bin}/tool-to-delete
</syntaxhighlight>
</syntaxhighlight>
</blockquote><!-- Package Management -->
</blockquote><!-- OS Package Management -->


= Publishing Modules =
= Creating/Hosting Packages =
<blockquote>
<blockquote>
== Public Modules ==
In order to hosting packages for OS-install, you simply need to expose the src using the module path.<br>
<blockquote>
It will be compiled for the platform automatically.
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
* See [[golang modules]] for creating modules, managing their requirements, and publishing to the public package index
<syntaxhighlight lang="bash">
* See [[golang module path]] for instructions on private package hosting
go mod tidy
</blockquote><!-- Project Requirements -->
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 -->

Latest revision as of 03:52, 20 June 2022

How to install executables,
manage project requirements,
and publish your project to the go index (or create a private module).

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

# there doesn't seem to be a managed way of doing this
rm ${GOBIN:=~/go/bin}/tool-to-delete

Creating/Hosting Packages

In order to hosting packages for OS-install, you simply need to expose the src using the module path.
It will be compiled for the platform automatically.

  • See golang modules for creating modules, managing their requirements, and publishing to the public package index
  • See golang module path for instructions on private package hosting