教程集 www.jiaochengji.com
教程集 >  Golang编程  >  golang教程  >  正文 Go语言配置文件解析器,类似于Windows下的INI文件.

Go语言配置文件解析器,类似于Windows下的INI文件.

发布时间:2021-12-21   编辑:jiaochengji.com
教程集为您提供Go语言配置文件解析器,类似于Windows下的INI文件.等资源,欢迎您收藏本站,我们将为您提供最新的Go语言配置文件解析器,类似于Windows下的INI文件.资源
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;"><path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"/></svg><h1 id="config">config</h1>

Package config is a Configuration file parser for INI format

包 config 是一个简洁方的,支持注释的Go语言配置文件解析器,类似于Windows下的INI文件.

配置文件形式为<code>[section]</code> 的段构成, 内部使用 <code>name=value</code>键值对
如果为指定段节点,则默认放入名为<code>[default]</code>的段当中.
“#”为注释的开头,可以放置于任意的单独一行中.

<h2 id="安装">安装</h2> <pre><code> go get github.com/lxmgo/config </code></pre> <h2 id="示例">示例</h2>

请查看 conf.ini 文件作为使用示例

<h2 id="使用规范">使用规范</h2>

示例配置文件:

<pre><code> [DEFAULT] host = act.wiki port = 8080 f64 = 64.1 [mysql] host = 127.0.0.1 [mongodb] host = 127.0.0.2 [redis] host = 127.0.0.3 push_key = key1,key2,key3,... [memcache] host = 127.0.0.4 </code></pre>

加载配置文件:

<pre><code> config, err := NewConfig("testdata/testini.ini") c.Int("port") // result is int 8080 c.Int64("port") // result is int64 8080 c.Float64("f64") // result is float64 64.1 c.String("host") // result is string "act.wiki" c.String("mysql.host") // result is string "127.0.0.1" c.String("redis.host") // result is string "127.0.0.3" c.Strings("redis.key") // result is []string{"key1","key2","key3",...} </code></pre> <h2 id="config-apis">config APIS:</h2> <pre><code> String(key string) string Strings(key string) []string Bool(key string) (bool, error) Int(key string) (int, error) Int64(key string) (int64, error) Float64(key string) (float64,error) Set(key string, value string) error </code></pre> <h2 id="更多信息">更多信息</h2> <ul><li>所有字符解析均使用小写的!</li></ul><h2 id="源码">源码</h2>

https://github.com/lxmgo/config

<h2 id="go交流群">Go交流群</h2>

185521558

到此这篇关于“Go语言配置文件解析器,类似于Windows下的INI文件.”的文章就介绍到这了,更多文章或继续浏览下面的相关文章,希望大家以后多多支持JQ教程网!

您可能感兴趣的文章:
Go语言配置文件解析器,类似于Windows下的INI文件.
如何读取yaml,json,ini等配置文件【Golang 入门系列九】
如何在C#中读写INI文件
golang几种常用配置文件使用方法总结(yaml、toml、json、xml、ini)
从零开始学习GO语言-搭建Go语言开发环境-快速开发入门第一个小程序
让我们一起认识YAML:YAML简介
go run main.go 参数_Go语言入门:Hello world
想系统学习GO语言(Golang
1.14 Go语言工程结构详述
[GO语言基础] 一.为什么我要学习Golang以及GO语言入门普及

[关闭]
~ ~