【发布时间】:2017-01-07 00:07:49
【问题描述】:
这是我的 yaml 文件:
db:
# table prefix
tablePrefix: tbl
# mysql driver configuration
mysql:
host: localhost
username: root
password: mysql
# couchbase driver configuration
couchbase:
host: couchbase://localhost
我使用 go-yaml 库将 yaml 文件解组为变量:
config := make(map[interface{}]interface{})
yaml.Unmarshal(configFile, &config)
配置值:
map[mysql:map[host:localhost username:root password:mysql] couchbase:map[host:couchbase://localhost] tablePrefix:tbl]
如何在没有预定义结构类型的情况下访问配置中的 db -> mysql -> 用户名 值
【问题讨论】:
-
请举例说明。您提供的代码有效,不会导致此错误。
-
我更新了我的问题@jimb