go读取toml文件配置文件
发布时间:2021-04-08 编辑:jiaochengji.com
教程集为您提供go读取toml文件配置文件等资源,欢迎您收藏本站,我们将为您提供最新的go读取toml文件配置文件资源
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.读取结果
到此这篇关于“go读取toml文件配置文件”的文章就介绍到这了,更多文章或继续浏览下面的相关文章,希望大家以后多多支持JQ教程网!您可能感兴趣的文章:
go读取toml文件配置文件
golang toml配置文件实例
2.golang: golang读取配置文件(toml文件形式)
golang几种常用配置文件使用方法总结(yaml、toml、json、xml、ini)
golang toml解析
Go语言从入门到精通 -【web项目实战篇】- 读取配置文件
golang之配置文件
golang基础学习-动态获取配置文件(viper)
go读取配置文件-viper
Golang配置文件解析-oozgconf
[关闭]