alyu / Configparser
Licence: other
Config ini file parser in Go
Stars: ✭ 40
Programming Languages
go
31211 projects - #10 most used programming language
Labels
Projects that are alternatives of or similar to Configparser
Go Deb Version
A golang library for parsing deb package versions
Stars: ✭ 21 (-47.5%)
Mutual labels: parser
Pbparser
Golang library for parsing protocol buffer (.proto) files
Stars: ✭ 30 (-25%)
Mutual labels: parser
Bookmark Parser
Find and parse Firefox/Chrome bookmark HTML and jsonlz4 file into useable JSON object or export as JSON file.
Stars: ✭ 31 (-22.5%)
Mutual labels: parser
Substitution Schedule Parser
Java library for parsing schools' substitution schedules. Supports multiple different systems mainly used in the German-speaking countries, including Untis, svPlan, and DAVINCI
Stars: ✭ 33 (-17.5%)
Mutual labels: parser
X509
A PHP library for X.509 public key certificates, attribute certificates, certification requests and certification path validation.
Stars: ✭ 27 (-32.5%)
Mutual labels: parser
Django Precise Bbcode
A Django application for parsing, displaying and editing BBCodes-based text contents.
Stars: ✭ 31 (-22.5%)
Mutual labels: parser
Anglesharp.css
👼 Library to enable support for cascading stylesheets in AngleSharp.
Stars: ✭ 27 (-32.5%)
Mutual labels: parser
Google Libphonenumber
The up-to-date and reliable Google's libphonenumber package for node.js.
Stars: ✭ 984 (+2360%)
Mutual labels: parser
Parsley
An exceptionally fast parser combinator library for Scala
Stars: ✭ 31 (-22.5%)
Mutual labels: parser
configparser
Package configparser provides a simple parser for reading/writing configuration (INI) files.
Supports reading/writing the INI file format in addition to:
- Reading/writing duplicate section names (ex: MySQL NDB engine's config.ini)
- Options without values (ex: can be used to group a set of hostnames)
- Options without a named section (ex: a simple option=value file)
- Find sections with regexp pattern matching on section names, ex: dc1.east.webservers where regex is '.webservers'
-
- = or : as value delimiter
package configparser_test
import (
"fmt"
"github.com/alyu/configparser"
"log"
)
// Read and modify a configuration file
func Example() {
// set a custom delimiter to be used for key/value seperation
configparser.Delimiter = "="
config, err := configparser.Read("/etc/config.ini")
if err != nil {
log.Fatal(err)
}
// Print the full configuration
fmt.Println(config)
// get a section
section, err := config.Section("MYSQLD DEFAULT")
if err != nil {
log.Fatal(err)
} else {
fmt.Printf("TotalSendBufferMemory=%s\n", section.ValueOf("TotalSendBufferMemory"))
// set new value
var oldValue = section.SetValueFor("TotalSendBufferMemory", "256M")
fmt.Printf("TotalSendBufferMemory=%s, old value=%s\n", section.ValueOf("TotalSendBufferMemory"), oldValue)
// delete option
oldValue = section.Delete("DefaultOperationRedoProblemAction")
fmt.Println("Deleted DefaultOperationRedoProblemAction: " + oldValue)
// add new options
section.Add("innodb_buffer_pool_size", "64G")
section.Add("innodb_buffer_pool_instances", "8")
}
// add a new section and options
section = config.NewSection("NDBD MGM")
section.Add("NodeId", "2")
section.Add("HostName", "10.10.10.10")
section.Add("PortNumber", "1186")
section.Add("ArbitrationRank", "1")
// find all sections ending with .webservers
sections, err := config.Find(".webservers$")
if err != nil {
log.Fatal(err)
}
for _, section := range sections {
fmt.Print(section)
}
// or
config.PrintSection("dc1.webservers")
sections, err = config.Delete("NDB_MGMD DEFAULT")
if err != nil {
log.Fatal(err)
}
// deleted sections
for _, section := range sections {
fmt.Print(section)
}
options := section.Options()
fmt.Println(options["HostName"])
// save the new config. the original will be renamed to /etc/config.ini.bak
err = configparser.Save(config, "/etc/config.ini")
if err != nil {
log.Fatal(err)
}
}
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].