教程集 www.jiaochengji.com
教程集 >  Golang编程  >  golang教程  >  正文 golang toml解析

golang toml解析

发布时间:2021-04-18   编辑:jiaochengji.com
教程集为您提供golang toml解析等资源,欢迎您收藏本站,我们将为您提供最新的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 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 %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解析”的文章就介绍到这了,更多文章或继续浏览下面的相关文章,希望大家以后多多支持JQ教程网!

您可能感兴趣的文章:
golang toml解析
2.golang: golang读取配置文件(toml文件形式)
golang几种常用配置文件使用方法总结(yaml、toml、json、xml、ini)
golang toml配置文件实例
go读取toml文件配置文件
使用docker部署一个带配置文件的golang项目
Golang配置文件解析-oozgconf
Go中配置文件读取的几种方式
golang之配置文件
项目结构设置

[关闭]
~ ~