I am interested in passing configuration values between multiple golang programs.
I have experimented with environment variables but they cannot be read by a different program than the one that set them.
I have tested and I am certain that the environment variable is being set and can be read in the same process that set it. Also, if I call the second process through the first it will print it:
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
os.Setenv("AVARIABLE", "12345")
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter text: ")
_, _ = reader.ReadString('
')
fmt.Println("exiting")
}
and
package main
import (
"fmt"
"os"
)
func main() {
fmt.Println(os.Getenv("AVARIABLE"))
}
The environment variable context is too narrow for my purpose.
I am considering these options:
Create a file at
/etc/profile.d/<filename>.sh
and runsource /etc/profile.d/<filename>.sh
in order to set the variable more globally.Create a file somewhere which anybody can read and avoid the environment variable issue.
Are there better ways? how should I proceed?