golang multiconfig 示例
参考资料:https://github.com/koding/multiconfig
测试代码:
package main import (
"fmt"
"github.com/koding/multiconfig"
) type Server struct {
Demo DemoConfig
} type DemoConfig struct {
Name string
Port int
Enabled bool
Users []string
} func main() {
fmt.Println("Hello, World!")
m := multiconfig.NewWithPath("config.toml") // supports TOML, JSON and YAML serverConf := new(Server)
err := m.Load(serverConf) // Check for error
if err != nil {
fmt.Println(err)
}
m.MustLoad(serverConf) // Panic's if there is any error fmt.Println(serverConf.Demo.Port)
fmt.Println(serverConf.Demo.Name)
fmt.Println(serverConf.Demo.Users)
}
配置文件:
[root@localhost multiconfig]# cat config.toml
[Demo]
Port =
Name = "test"
Users = ["aaa", "bbb", "ccc"]
运行结果:
[root@localhost multiconfig]# go run test.go
Hello, World! test
[aaa bbb ccc]
golang multiconfig 示例的更多相关文章
- Golang爬虫示例包系列教程(一):pedaily.com投资界爬虫
Golang爬虫示例包 文件结构 自己用Golang原生包封装了一个爬虫库,源码见go get -u -v github.com/hunterhug/go_tool/spider ---- data ...
- Golang gRPC 示例
1.安装gRPC runtime go get google.golang.org/grpc 为了自动生成Golang的gRPC代码,需要安装protocal buffers compiler以及对应 ...
- golang语言示例
package main import "fmt" /* my first programmer in go */ func fib(n int) int{ if n<2{ ...
- golang json 示例
jsonStr, err := client.Get( deviceIdKey ).Result() if err == redis.Nil { deviceIds = []string{device ...
- golang server示例
一个简单的web服务器 package main import ( "fmt" "log" "net/http" ) func main() ...
- 【Networking】gRPC golang 相关资料
参考资料: Golang gRPC 示例: http://www.cnblogs.com/YaoDD/p/5504881.html grpc golang学习心得(1)----安装与测试: ht ...
- Drone 持续集成实践 - 基于 Gogs,以 Golang 为例
Drone 官方示例 - Example Go project 用 Docker 部署 Go 服务器 Golang 官方示例 - outyet 一个生产环境的例子 用 rsync 复制文件的方式进行部 ...
- 理解Golang组件protobuf
什么是protobuf protocol buffers 是一种语言无关.平台无关.可扩展的序列化结构数据的方法,它可用于(数据)通信协议.数据存储等.是一种灵活,高效,自动化机制的结构数据序列化方法 ...
- 使用go语言后的感受
前两天我说过为了学习go语言去学习了一遍python,当我完成了python的学习后,昨天中午就去学习了go语言.以下简称之为golang. 我用的操作系统是windows xp,golang对xp还 ...
随机推荐
- shell 十三问
经典的Shell十三问 摘选整理自:http://bbs.chinaunix.net/thread-218853-1-1.htmlhttps://github.com/wzb56/13_questio ...
- 两种 HTTP 方法:GET 和 POST
区别 GET POST 可见性 数据在 URL 中对所有人都是可见的. post 方式通过body体进行传输,数据不会显示在 URL 中. 安全性 与 POST 相比,GET 的安全性较差,因为所发送 ...
- Fortify Audit Workbench 笔记索引
Password Management: Password in Configuration File(明文存储密码) https://www.cnblogs.com/mahongbiao/p/124 ...
- centos7安装单机环境redis3.2
本次安装的系统版本如下: [root@zhangqinglei ~]# cat /etc/redhat-releaseCentOS Linux release 7.5.1804 (Core) [roo ...
- Python os.fpathconf() 方法
概述 os.fpathconf() 方法用于返回一个打开的文件的系统配置信息.高佣联盟 www.cgewang.com Unix上可用. 语法 fpathconf()方法语法格式如下: os.fpat ...
- PHP is_link() 函数
定义和用法 The is_link() 函数检查指定的文件是否是一个连接. 如果文件是一个连接,该函数返回 TRUE. 语法 is_link(file) 参数 描述 file 必需.规定要检查的文件. ...
- 承诺会计/预留款会计(commitment accounting/Encumbrance Accounting) in AX 2012
作者:umfish 博文 http://blog.csdn.net/umfish/article/details/7751397 如果要使用Encmubrance Accounting, 需要先在G ...
- Qt 之 Graphics View Framework 简介
Graphics View Framework 交互式 2D 图形的 Graphics View 框架概述.自 Qt4.2 中引入了 Graphics View,以取代其前身 QCanvas.Grap ...
- 关于idea 在创建maven 骨架较慢问题解决
在设置中->maven>runner>VM Options 粘贴 -DarchetypeCatalog=internal 其中 -D archetype:原型,典型的意思 ( ...
- asp.net core 3.1多种身份验证方案,cookie和jwt混合认证授权
开发了一个公司内部系统,使用asp.net core 3.1.在开发用户认证授权使用的是简单的cookie认证方式,然后开发好了要写几个接口给其它系统调用数据.并且只是几个简单的接口不准备再重新部署一 ...