doujiyuan0211 2016-11-29 13:08
浏览 130
已采纳

使用viper的配置文件在GO中提供了空值

i am new in Go and using viper for configuration management

configuration file looks like (config.yaml)

SD_ORIGIN : web url
API_TRACKING_ID : 77xxx1
API_TOKEN : sdsaxxxdfds123

And using the go code to read the value but getting null value while i read code snippet as :-

    viper.SetConfigName("config")
    viper.AddConfigPath(".")
    err := viper.ReadInConfig()
    if err != nil {
        fmt.Println("Config not found...")
    }
}

var apiTrackingID = viper.GetString("API_TRACKING_ID")

Please help to find the issue in my config file or implementation in Go.

  • 写回答

1条回答 默认 最新

  • dragon87836215 2016-11-29 13:21
    关注

    better to check this https://github.com/spf13/viper the code snippet looks good ..may be there can be issue with $GOPATH and $GOHOME

    and your config.yaml file is not proper double quotes are missing.

    API_TOKEN : "sdsaxxxdfds123"
    

    It has to be like this, hope this resolves your problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?