How to set environment variables that last

前端 未结 4 1778
甜味超标
甜味超标 2020-12-11 04:48

I\'m trying to set some environment variables on my machine using Go OS

    err := os.Setenv(\"DBHOST\", dbHostLocal)
    if err != nil {
        log.Fatalf(         


        
4条回答
  •  囚心锁ツ
    2020-12-11 05:22

    Short: It is not possible. You can't change the environment of your parent process. You can only change your own and pass it to your children.

    What you should do is maintain a config file. There are plenty of go config libs out there: ini, yaml, etc.

    If your program changes the config, save it to disk after each change or one in a while or when the process exits.

提交回复
热议问题