alecuba16 / go-configparser-lowercase

An implementation of the Python ConfigParser in Go. Default profile should be in lowercase.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go-configparser Build Status

Go implementation of the Python ConfigParser class.

This can parse Python-compatible ConfigParser config files, including support for option interpolation.

Setup

  import (
    "github.com/alecuba16/go-configparser-lowercase"
  )

Parsing configuration files

It's easy to parse a configuration file.

  p, err := configparser.NewConfigParserFromFile("example.cfg")
  if err != nil {
    ...
  }

Methods

The ConfigParser implements most of the Python ConfigParser API

  v, err := p.Get("section", "option")
  err = p.Set("section", "newoption", "value")

  s := p.Sections()

Interpolation

The ConfigParser implements interpolation in the same format as the Python implementation.

Given the configuration

  [DEFAULTS]
  dir: testing

  [testing]
  something: %(dir)s/whatever
  v, err := p.GetInterpolated("testing, something")

It's also possible to override the values to use when interpolating values by providing a Dict to lookup values in.

  d := make(configparser.Dict)
  d["dir"] = "/a/non/existent/path"
  result, err := p.GetInterpolatedWithVars("testing", "something", d)

Will get testing/whatever as the value

About

An implementation of the Python ConfigParser in Go. Default profile should be in lowercase.

License:MIT License


Languages

Language:Go 100.0%