Jquery中文网 www.jquerycn.cn
Jquery中文网 >  后端编程  >  Go语言  >  正文 go读取toml文件配置文件

go读取toml文件配置文件

发布时间:2021-04-08   编辑:www.jquerycn.cn
jquery中文网为您提供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文件配置文件
2.golang: golang读取配置文件(toml文件形式)
golang几种常用配置文件使用方法总结(yaml、toml、json、xml、ini)
golang toml解析
Go语言爱好者周刊:第 78 期 — 这道关于 goroutine 的题
golang模块viper读取配置文件
go 单元测试时读取配置文件
go 获取文件的md5值
go配置文件读取
Golang库 - viper读取配置文件

[关闭]