Viper使用简介-基于Tendermint

本文介绍了Tendermint如何利用Viper进行配置管理。Viper是一个全功能的Go语言配置解决方案,允许设置配置文件名称、路径,并能自动识别多种后缀的配置文件。在使用过程中,可以通过SetConfigName和AddConfigPath添加配置文件信息,ReadInConfig读取内容。Viper提供GetString、GetBool等方法读取单个变量,以及通过Unmarshal方法将配置信息映射到结构体。在结构体映射时,需使用'mapstructure:"seeds"'注解帮助Viper找到对应的变量。
摘要由CSDN通过智能技术生成

Tendermint需要配置一些属性的时候是在config.toml中配置的,刚开始没看明白toml配置文件是如何生效的,深入了解了一下做个记录。

原来tnedermint使用了viper(ˈvaɪpə(r),现在看到i都得确认下发什么音)开源项目,那么viper是什么呢

看下github的解释:https://github.com/spf13/viper

Viper is a complete configuration solution for Go applications including 12-Factor apps. It is designed to work within an application, and can handle all types of configuration needs and formats. It supports:

setting defaults
reading from JSON, TOML, YAML, HCL, and Java properties config files
live watching and re-reading of config files (optional)
reading from environment variables
reading from remote config systems (etcd or Consul), and watching changes
reading from command line flags
reading from buffer
setting explicit values
Viper can be thought of as a registry for all of your applications configuration needs.

(csdn改版了啊,这个框可以再编辑了

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值