Passing configuration values between multiple Golang programs
<p>I am interested in passing configuration values between multiple golang programs.  </p>

<p>I have experimented with environment variables but they cannot be read by a different program than the one that set them. </p>

<p>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:</p>

<pre><code>package main

import (
    "bufio"
    "fmt"
    "os"
)    

func main() {
    os.Setenv("AVARIABLE", "12345")

    reader := bufio.NewReader(os.Stdin)
    fmt.Print("Enter text: ")
    _, _ = reader.ReadString('\n')
    fmt.Println("exiting")
}              
</code></pre>

<p>and </p>

<pre><code>package main

import (
    "fmt"
    "os"
)

func main() {
    fmt.Println(os.Getenv("AVARIABLE"))
}
</code></pre>

<p>The environment variable context is too narrow for my purpose.</p>

<p>I am considering these options: </p>

<ol>
<li><p>Create a file at <code>/etc/profile.d/&lt;filename&gt;.sh</code> and run <code>source /etc/profile.d/&lt;filename&gt;.sh</code> in order to set the variable more globally. </p></li>
<li><p>Create a file somewhere which anybody can read and avoid the environment variable issue. </p></li>
</ol>

<p>Are there better ways? how should I proceed?</p>