kelseyhightower / envconfig

Golang library for managing configuration data from environment variables
MIT License
5.02k stars 377 forks source link

Getting Env Variables Not Working. #112

Closed mdere closed 5 years ago

mdere commented 6 years ago

Morning - so I have the following:

type Specification struct {
    Hostname        string
    // RDBMSDBUser     string
    // RDBMSDBPassword string
}

func GetConf() Specification {
    var s Specification
    err := envconfig.Process("myapp", &s)
    if err != nil {
        panic(err.Error())
    }
    log.Log("#######################")
    log.Log(s)
    log.Log(&s)

    // s.Hostname, s.RDBMSDBUser, s.RDBMSDBPassword
    return s
}

and I am running my app in docker - so it is running it as root - so I assume I need to export those variables as root, also I did it as my primary user too.

root@mdere-VirtualBox:/home/mdere# echo $MYAPP_HOSTNAME
localhost:8080

mdere:~$ echo $MYAPP_HOSTNAME
localhost:8080

the logs are spitting out {} or &{} for s variable

schahal commented 6 years ago

and I am running my app in docker

But the echo of your environment variable seem to be run on the host. Are you sure you're passing/setting the environment variable $MYAPP_HOSTNAME into the docker container as well?

teepark commented 5 years ago

I can get your example working @mdere, I think as @schahal suggested it's a matter of having the environment variables actually visible to your application.