Go: 从文件中读取配置

用到的包:

"github.com/spf13/viper"

 步骤:

1.新建一个yml文件:

假如这里配置服务器端口和数据库的配置。类似于springboot的application.yml

 2. 编写初始化配置函数:

并在main()中调用:

 

3. 在实际要从文件中读取配置的地方编写相应的代码:

用起来是真香~~ 

发布了356 篇原创文章 · 获赞 67 · 访问量 14万+

猜你喜欢

转载自blog.csdn.net/qq_39969226/article/details/104664347