本文主要是介绍golang toml解析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
TOML 的全称是 Tom’s Obvious, Minimal Language,因为它的作者是 GitHub 联合创始人 Tom Preston-Werner。
TOML 的目标是成为一个极简的配置文件格式。TOML 被设计成可以无歧义地被映射为哈希表,从而被多种语言解析。
github: https://github.com/BurntSushi/toml
安装:go get github.com/BurntSushi/toml
package mainimport ("fmt""github.com/BurntSushi/toml""log"
)type songInfo struct {Name stringDuration int
}type config struct {Bc stringSong songInfo
}func test_toml() {var cg configvar cpath string = "./example.toml"if _, err := toml.DecodeFile(cpath, &cg); err != nil {log.Fatal(err)}fmt.Printf("%v %v\n", cg.Bc, cg.Song.Name)
}func main() {test_toml()
}/*
result:
robert-homedeMacBook-Pro:toml robert-home$ go run test_toml.go
坐标北京 北京.北京*/
example.toml
Bc = “坐标北京”
[song]
Name = “北京.北京”
Duration = 900
这篇关于golang toml解析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!