Golang environments: Difference between revisions
From wikinotes
(Created page with "= Documentation = <blockquote> {| class="wikitable" |- | environment variables || https://pkg.go.dev/cmd/go#hdr-Environment_variables |- |} </blockquote><!-- Documentation -->...") |
No edit summary |
||
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Go uses a small number of environment variables to configure builds, modules.<br> | |||
Modules are explicit/sealed off, there isn't much of a case for tools like nix unless you're using extensions or alternative compilers. | |||
= Documentation = | = Documentation = | ||
<blockquote> | <blockquote> | ||
Line 7: | Line 10: | ||
|} | |} | ||
</blockquote><!-- Documentation --> | </blockquote><!-- Documentation --> | ||
=== Locations === | |||
<blockquote> | |||
{| class="wikitable" | |||
|- | |||
| <code>~/.config/go/env</code> || 'go env' set environment variables | |||
|- | |||
|} | |||
</blockquote><!-- Locations --> | |||
= Environment Variables = | = Environment Variables = | ||
Line 13: | Line 25: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
GOPATH= | GOPATH= | ||
GOBIN= | GOBIN=~/go/bin # where go installed executables should go | ||
GOPROXY= | GOPROXY= | ||
</syntaxhighlight> | |||
private/privacy options | |||
<syntaxhighlight lang="bash"> | |||
# packages that should not be indexed publicly | |||
# (reused by GONOPROXY, GONOSUMDB if they are not set) | |||
GOPRIVATE=*.corp.example.com,rsc.io/private | |||
GONOPROXY=*.corp.example.com,rsc.io/private | |||
GONOSUMDB=*.corp.example.com,rsc.io/private | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- Environment Variables --> | </blockquote><!-- Environment Variables --> | ||
Line 22: | Line 42: | ||
= Go Env = | = Go Env = | ||
<blockquote> | <blockquote> | ||
<code>go env</code> lets you set/persist go environment variables.<br> | |||
They will be loaded in new shells automatically. | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
go env -w GOBIN=/foo/bar/bin # set default envvar val within environment | go env -w GOBIN=/foo/bar/bin # set default envvar val within environment |
Latest revision as of 03:58, 20 June 2022
Go uses a small number of environment variables to configure builds, modules.
Modules are explicit/sealed off, there isn't much of a case for tools like nix unless you're using extensions or alternative compilers.
Documentation
environment variables https://pkg.go.dev/cmd/go#hdr-Environment_variables
Locations
~/.config/go/env
'go env' set environment variables
Environment Variables
A small subset of useful environment variables.
GOPATH= GOBIN=~/go/bin # where go installed executables should go GOPROXY=private/privacy options
# packages that should not be indexed publicly # (reused by GONOPROXY, GONOSUMDB if they are not set) GOPRIVATE=*.corp.example.com,rsc.io/private GONOPROXY=*.corp.example.com,rsc.io/private GONOSUMDB=*.corp.example.com,rsc.io/private
Go Env
go env
lets you set/persist go environment variables.
They will be loaded in new shells automatically.go env -w GOBIN=/foo/bar/bin # set default envvar val within environment go env -u GOBIN # unset environment variable set by 'go env'