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 main
import (
"fmt"
"github.com/BurntSushi/toml"
"log"
)
type songInfo struct {
Name string
Duration int
}
type config struct {
Bc string
Song songInfo
}
func test_toml() {
var cg config
var cpath string = "./example.toml"
if _, err := toml.DecodeFile(cpath, &cg); err != nil {
log.Fatal(err)
}
fmt.Printf("%v %vn", 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
参与评论
手机查看
返回顶部