Golang read the pkg configured by the INI (read config file)

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Today I wrote a go to read the INI file package, has been uploaded to GitHub top, convenient for everyone to use, mainly read the configuration file method. The bottom is a simple document

The official website

Describe

Using Goini, it is easier to read the INI configuration file of Go and various configuration files according to the specific format.

Installation method

gp get github.com/widuu/goini

How to use

INI configuration file grid style column

[database]username = rootpassword = passwordhostname = localhost[admin]username = rootpassword = password[nihao]username = rootpassword = password

Initialization

conf := goini.SetConfig("./conf/conf.ini") //goini.SetConfig(filepath) 其中filepath是你ini 配置文件的所在位置

Get Individual configuration information

username := conf.GetValue("database", "username") //database是你的[section],username是你要获取值的key名称fmt.Println(username) //root

Delete a configuration message

conf.DeleteValue("database", "username")    //username 是你删除的keyusername = 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 添加配置信息如果存在[section]则添加或者修改对应的值,如果不存在则添加section

Get all configuration information

conf.ReadList() //返回[]map[string]map[string]string的格式 即setion=>key->value

Without permission, do not reprint this site any article: Micro network»golang read the INI configuration pkg (read the configuration file)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.