迷失之钥
首页
视频
文章
捐赠
登陆
注册
go语言yaml配置载入
作者:cyanBone
发表时间:2020年02月08日
# go语言yaml配置载入 ## 程序代码 ```golang package main import ( "io/ioutil" "fmt" "os" "gopkg.in/yaml.v2" ) type configs struct { Wechat struct { Id string Secret string Token string } Oauth struct { token string send string Id string Secret string Scope string Type string } Address string } var cfs configs func main() { c, err := ioutil.ReadFile("./conf.yaml") if err != nil { os.Exit(1) } err = yaml.Unmarshal(c, &cfs) if err != nil { os.Exit(1) } fmt.Println(cfs) } ``` ## yaml 文件 ```yaml #访问地址 address: xxx #oauth信息 oauth: type: xxx id: 2 secret: xxx scope: send: http://xxx token: http://xxx #微信信息 wechat: id: xxx secret: xxx token: xxx ```
获取最新的本网站资讯
最新的文章和信息动态快速的了解
订阅资讯
立即注册,开始了解更多