Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/widuu/goini
golang读取ini配置文件
https://github.com/widuu/goini
Last synced: about 1 month ago
JSON representation
golang读取ini配置文件
- Host: GitHub
- URL: https://github.com/widuu/goini
- Owner: widuu
- License: apache-2.0
- Created: 2014-03-28T13:18:12.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2022-11-16T00:39:38.000Z (about 2 years ago)
- Last Synced: 2024-12-07T10:10:24.780Z (about 2 months ago)
- Language: Go
- Homepage: http://www.widuu.com/archives/02/961.html
- Size: 11.7 KB
- Stars: 83
- Watchers: 10
- Forks: 42
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
goini
========
[![Build Status](https://travis-ci.org/widuu/goini.svg?branch=master)](https://travis-ci.org/widuu/goini)**[The official website](http://www.widuu.com)**
##描述使用goini更简单的读取go的ini配置文件以及根据特定格式的各种配置文件。
##安装方法
gp get github.com/widuu/goini
##使用方法
>ini配置文件格式样列
[database]
username = root
password = password
hostname = localhost
[admin]
username = root
password = password
[nihao]
username = root
password = password>初始化
conf := goini.SetConfig("./conf/conf.ini") //goini.SetConfig(filepath) 其中filepath是你ini 配置文件的所在位置
>获取单个配置信息
username := conf.GetValue("database", "username") //database是你的[section],username是你要获取值的key名称
fmt.Println(username) //root>删除一个配置信息
conf.DeleteValue("database", "username") //username 是你删除的key
username = conf.GetValue("database", "username")
if len(username) == 0 {
fmt.Println("username is not exists") //this stdout username is not exists
}>添加一个配置信息
conf.SetValue("database", "username", "widuu")
username = conf.GetValue("database", "username")
fmt.Println(username) //widuu 添加配置信息如果存在[section]则添加或者修改对应的值,如果不存在则添加section>获取所有配置信息
conf.ReadList() //返回[]map[string]map[string]string的格式 即setion=>key->value
---
goini
========##About
使用goini更简单的读取go的ini配置文件以及根据特定格式的各种配置文件。
##install
gp get github.com/widuu/goini
##use example
>conf.ini
[database]
username = root
password = password
hostname = localhost
[admin]
username = root
password = password
[nihao]
username = root
password = password>initialize
conf := goini.SetConfig("./conf/conf.ini") //goini.SetConfig(filepath) filepath = directory+file
>To obtain a single configuration information
username := conf.GetValue("database", "username") //username is your key you want get the value
fmt.Println(username) //root>To delete a configuration information
conf.DeleteValue("database", "username") //username is your delete the key
username = conf.GetValue("database", "username")
if len(username) == 0 {
fmt.Println("username is not exists") //this stdout username is not exists
}>Add a configuration information
conf.SetValue("database", "username", "widuu")
username = conf.GetValue("database", "username")
fmt.Println(username) //widuu Adding/section configuration information if there is to add or modify the value of the corresponding, if there is no add section>Get all the configuration information
conf.ReadList() //return []map[string]map[string]string example:setion=>key->value