栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

(继续)如何使用toml文件?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

(继续)如何使用toml文件?

首先获取BurntSushi的toml解析器:

go get github.com/BurntSushi/toml

BurntSushi解析toml并将其映射到结构,这就是您想要的。

然后执行以下示例并从中学习:

package mainimport (    "github.com/BurntSushi/toml"    "log")var tomlData = `title = "config"[feature1]enable = trueuserids = [  "12345", "67890"][feature2]enable = false`type feature1 struct {    Enable  bool    Userids []string}type feature2 struct {    Enable bool}type tomlConfig struct {    Title string    F1    feature1 `toml:"feature1"`    F2    feature2 `toml:"feature2"`}func main() {    var conf tomlConfig    if _, err := toml.Depre(tomlData, &conf); err != nil {        log.Fatal(err)    }    log.Printf("title: %s", conf.Title)    log.Printf("Feature 1: %#v", conf.F1)    log.Printf("Feature 2: %#v", conf.F2)}

请注意

tomlData
和及其如何映射到该
tomlConfig
结构。

在https://github.com/BurntSushi/toml中查看更多示例



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/403803.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号