版权声明:by DongBao https://blog.csdn.net/aaaadong/article/details/91386088
1.准备引用项目
go get github.com/BurntSushi/toml
2.代码
package main
import (
"fmt"
"github.com/BurntSushi/toml"
)
func main() {
fpath := "/Users/dong/Desktop/config.toml"
var conf Config
if _, err := toml.DecodeFile(fpath, &conf); err != nil {
fmt.Println("decode config file err")
}
fmt.Println(conf)
}
type Config struct {
Common Common
}
type Common struct {
Base string
Addr string
}
3.toml文件 config.toml
# This is a TOML document.
# dev(debug) config.
[common]
base = "http://localhost"
addr = ":5000"
4.读取结果