参考资料: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 示例的更多相关文章

  1. Golang爬虫示例包系列教程(一):pedaily.com投资界爬虫

    Golang爬虫示例包 文件结构 自己用Golang原生包封装了一个爬虫库,源码见go get -u -v github.com/hunterhug/go_tool/spider ---- data ...

  2. Golang gRPC 示例

    1.安装gRPC runtime go get google.golang.org/grpc 为了自动生成Golang的gRPC代码,需要安装protocal buffers compiler以及对应 ...

  3. golang语言示例

    package main import "fmt" /* my first programmer in go */ func fib(n int) int{ if n<2{ ...

  4. golang json 示例

    jsonStr, err := client.Get( deviceIdKey ).Result() if err == redis.Nil { deviceIds = []string{device ...

  5. golang server示例

    一个简单的web服务器 package main import ( "fmt" "log" "net/http" ) func main() ...

  6. 【Networking】gRPC golang 相关资料

    参考资料: Golang gRPC 示例:  http://www.cnblogs.com/YaoDD/p/5504881.html grpc golang学习心得(1)----安装与测试:   ht ...

  7. Drone 持续集成实践 - 基于 Gogs,以 Golang 为例

    Drone 官方示例 - Example Go project 用 Docker 部署 Go 服务器 Golang 官方示例 - outyet 一个生产环境的例子 用 rsync 复制文件的方式进行部 ...

  8. 理解Golang组件protobuf

    什么是protobuf protocol buffers 是一种语言无关.平台无关.可扩展的序列化结构数据的方法,它可用于(数据)通信协议.数据存储等.是一种灵活,高效,自动化机制的结构数据序列化方法 ...

  9. 使用go语言后的感受

    前两天我说过为了学习go语言去学习了一遍python,当我完成了python的学习后,昨天中午就去学习了go语言.以下简称之为golang. 我用的操作系统是windows xp,golang对xp还 ...

随机推荐

  1. 800页的《数据随想录》PDF版电子书|百度网盘免费下载|数据科学领域必读

    百度网盘免费下载|<数据随想录> 提取码:51y7 本电子书内容包含从数据埋点到数据可视化整个链条的内容,同时,也整理了很多小伙伴们在交流社区中常问到的问题<数据百问>系列 数 ...

  2. Day01_WebCrawler(网络爬虫)

    学于黑马和传智播客联合做的教学项目 感谢 黑马官网 传智播客官网 微信搜索"艺术行者",关注并回复关键词"webcrawler"获取视频和教程资料! b站在线视 ...

  3. Python打印到屏幕_读取键盘输入

    Python打印到屏幕_读取键盘输入: print( ): 打印输出括号中的值 print("hello") # hello strs = 'hello' print(" ...

  4. Numpy random函数

    import numpy as np # 生成一个随机数组 np.random.randint(0,6,3) # array([1, 1, 3]) # 生成一个随机数组(二维数组) np.random ...

  5. odoo12的视图常见属性和操作

    1.菜单视图属性: 常用属性: name是展示在用户界面中的菜单项标题 action是点击菜单项时运行的窗口操作的XML ID parent是父级菜单项的XML ID.本例中父级项由其它模块创建,因此 ...

  6. windows:shellcode 远程线程hook/注入(五)

    前面几篇文章介绍了通过APC注入.进程注入.windows窗口处理函数回调.kernercallback回调执行shellcode,今天继续介绍通过heap Spray(翻译成中文叫堆喷射)执行she ...

  7. 从别人的代码中学习golang系列--03

    这篇博客还是整理从https://github.com/LyricTian/gin-admin 这个项目中学习的golang相关知识. 作者在项目中使用了 github.com/casbin/casb ...

  8. lamt环境搭建

    目录 lamt环境搭建 安装apache 安装mysql 安装tomcat 修改配置文件 lamt环境搭建 环境说明: 系统 IP 需要安装的服务 centos7 192.168.32.125 htt ...

  9. Oracle APEX 发送邮件

    1.网络服务安全设置 Oracle 11gR2的版本,可能导致邮件发送失败(ORA-24247: network access denied by access control list (ACL)) ...

  10. Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile (default-testCompile) on project docker_springcloud_demo: Fatal error compiling: 无效的标记: -parameters -> [Help 1]

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile (def ...