Help us shape the future of Go! Take the 2026 Go Developer Survey

mini

package module
v0.0.0-...-fc4e6a1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2015 License: MIT Imports: 9 Imported by: 0

README

GoDoc

Mini is a simple ini configuration file parser.

The ini syntax supported includes:

  • The standard name=value
  • Comments on new lines starting with # or ;
  • Blank lines
  • Sections labelled with [sectionname]
  • Split sections, using the same section in more than one place
  • Encoded strings, strings containing \n, \t, etc...
  • Array values using repeated keys named in the form key[]=value
  • Global key/value pairs that appear before the first section

Repeated keys, that aren't array keys, replace their previous value.

To use simply:

% go get github.com/fogcreek/mini

copyright © 2015 Fog Creek Software, Inc.

Documentation

Overview

Package mini implements a simple ini file parser.

The ini syntax supported includes:

* The standard name=value * Comments on new lines starting with # or ; * Blank lines * Sections labelled with [sectionname] * Split sections, using the same section in more than one place * Encoded strings, strings containing \n, \t, etc... * Array values using repeated keys named in the form key[]=value * Global key/value pairs that appear before the first section

Repeated keys, that aren't array keys, replace their previous value.

copyright © 2015 Fog Creek Software, Inc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config holds the contents of an ini file organized into sections.

func LoadConfiguration

func LoadConfiguration(path string) (*Config, error)

LoadConfiguration takes a path, treats it as a file and scans it for an ini configuration.

func LoadConfigurationFromReader

func LoadConfigurationFromReader(input io.Reader) (*Config, error)

LoadConfigurationFromReader takes a reader and scans it for an ini configuration. The caller should close the reader.

func (*Config) Boolean

func (config *Config) Boolean(key string, def bool) bool

Boolean looks for the specified key and returns it as a bool. If not found the default value def is returned.

func (*Config) BooleanFromSection

func (config *Config) BooleanFromSection(sectionName string, key string, def bool) bool

BooleanFromSection looks for the specified key and returns it as a boolean. If not found the default value def is returned.

func (*Config) DataFromSection

func (config *Config) DataFromSection(sectionName string, data interface{}) bool

DataFromSection reads the values of a section into a struct. The values should be of the types:

bool
string
[]string
int64
[]int64
float64
[]float64

Values that are missing in the section are not set, and values that are missing in the struct but present in the section are ignored.

func (*Config) Float

func (config *Config) Float(key string, def float64) float64

Float looks for the specified key and returns it as a float. If not found the default value def is returned.

func (*Config) FloatFromSection

func (config *Config) FloatFromSection(sectionName string, key string, def float64) float64

FloatFromSection looks for the specified key and returns it as a float. If not found the default value def is returned.

func (*Config) Floats

func (config *Config) Floats(key string) []float64

Floats looks for an array of floats under the provided key. If no matches are found nil is returned.

func (*Config) FloatsFromSection

func (config *Config) FloatsFromSection(sectionName string, key string) []float64

FloatsFromSection looks for an array of floats in the provided section and under the provided key. If no matches are found nil is returned.

func (*Config) InitializeFromPath

func (config *Config) InitializeFromPath(path string) error

InitializeFromPath takes a path, treats it as a file and scans it for an ini configuration.

func (*Config) InitializeFromReader

func (config *Config) InitializeFromReader(input io.Reader) error

InitializeFromReader takes a reader and scans it for an ini configuration. The caller should close the reader.

func (*Config) Integer

func (config *Config) Integer(key string, def int64) int64

Integer looks for the specified key and returns it as an int. If not found the default value def is returned.

func (*Config) IntegerFromSection

func (config *Config) IntegerFromSection(sectionName string, key string, def int64) int64

IntegerFromSection looks for the specified key and returns it as an int64. If not found the default value def is returned.

func (*Config) Integers

func (config *Config) Integers(key string) []int64

Integers looks for an array of ints under the provided key. If no matches are found nil is returned.

func (*Config) IntegersFromSection

func (config *Config) IntegersFromSection(sectionName string, key string) []int64

IntegersFromSection looks for an array of integers in the provided section and under the provided key. If no matches are found nil is returned.

func (*Config) Keys

func (config *Config) Keys() []string

Keys returns all of the global keys in the config.

func (*Config) KeysForSection

func (config *Config) KeysForSection(sectionName string) []string

KeysForSection returns all of the keys found in the section named sectionName.

func (*Config) SectionNames

func (config *Config) SectionNames() []string

SectionNames extracts names of all configuration sections that Config currently contains.

func (*Config) String

func (config *Config) String(key string, def string) string

String looks for the specified key and returns it as a string. If not found the default value def is returned.

func (*Config) StringFromSection

func (config *Config) StringFromSection(sectionName string, key string, def string) string

StringFromSection looks for the specified key and returns it as a string. If not found the default value def is returned.

func (*Config) Strings

func (config *Config) Strings(key string) []string

Strings looks for an array of strings under the provided key. If no matches are found nil is returned. If only one matches an array of 1 is returned.

func (*Config) StringsFromSection

func (config *Config) StringsFromSection(sectionName string, key string) []string

StringsFromSection returns the value of an array key, if the value of the key is a non-array, then that value is returned in an array of length 1

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL