package main import ( "log" "testing" "github.com/ghodss/yaml" ) func TestApp(t *testing.T) { by := []byte(`settings: application: # dev开发环境 test测试环境 prod线上环境 mode: dev # 服务器ip,默认使用 0.0.0.0 host: 0.0.0.0 logger: # 日志存放路径 path: temp/logs `) var data map[string]interface{} log.Println(string(by)) err := yaml.Unmarshal(by,&data) log.Println("v,err===>",data,err) }
output ==>
D:\code\go\gotmp>go test
2021/06/08 21:35:38 settings:
application:
# dev开发环境 test测试环境 prod线上环境
mode: dev
# 服务器ip,默认使用 0.0.0.0
host: 0.0.0.0
# 服务名称
name: testApp
# 端口号
port: 8000 # 服务端口号
readtimeout: 1
writertimeout: 2
# 数据权限功能开关
enabledp: false
logger:
# 日志存放路径
path: temp/logs
# 控制台日志
stdout: true
# 日志等级
level: all
# 业务日志开关
enabledbus: true
2021/06/08 21:35:38 v,err===> map[settings:map[application:map[enabledp:false host:0.0.0.0 mode:dev name:testApp port:8000 readtimeout:1 writertimeout:2] logger:map[enabledbus:true level:all path:temp/logs stdout:true]]] <nil>
PASS
ok gotmp 0.652s
D:\code\go\gotmp>go test
2021/06/08 21:36:09 settings:
application:
# dev开发环境 test测试环境 prod线上环境
mode: dev
# 服务器ip,默认使用 0.0.0.0
host: 0.0.0.0
logger:
# 日志存放路径
path: temp/logs
2021/06/08 21:36:09 v,err===> map[settings:map[application:map[host:0.0.0.0 mode:dev] logger:map[path:temp/logs]]] <nil>
PASS
ok gotmp 0.500s
原文:https://www.cnblogs.com/eiguleo/p/14864576.html