Description
As Go keep Growing the Go Environment Variables for Configuration is getting complex and their are some programs that requires specific configuration and it may mess up the default environment variables or tedious to setup so I propose we should add a file called go.environment
which can be used instead of the default variables or the manual setup.
In the go.environment
file
package < directory name > // package may not be needed
version: < go version >
<go variable and their values>
goos: linux
goarch: ….
goroot: …..
when dealing with a variable that can accept multiple of Values
goexperiment: {
boringcrypto, arena, unified
}
Or
goexperiment: { boringcrypto, arena, unified}
with the command go env init
or go env init < directory >
Constraints
The go.environment
file can either work or initiate if the directory does not contain package main
in any go file since it won’t be useful for any libraries to have it
if GOOS=linux go build *.go
This will argument will be treated first than what’s in the file.
We could add comments so it can be easy store some variables when needed // goos:
then force the compiler to check for any empty variable goos:
or
If a variable is empty the compiler ignore it and use the default one
If there’s an invalid variable according to the go compiler version it’s either it ignore it or output an error
commands like go env goos=linux
modify the file
Activity
seankhliao commentedon Jan 1, 2023
Duplicate of #57179