Documentation ¶
Overview ¶
Package config is used to read and write configuration files.
Configuration files are similar to Windows INI files. They store a list of properties (key/value pairs); they may also be grouped into sections.
The basic syntax of a configuration file is as follows:
name1=value1 name2=value2 ... [section] name3=value3 name4=value4 ...
Properties not in a section are placed in the unnamed (empty "") section.
Index ¶
- Variables
- func ReadFunc(reader io.Reader, fn func(sect, name string, valu interface{})) error
- func Write(writer io.Writer, conf Config) error
- func WriteTyped(writer io.Writer, conf TypedConfig) error
- type Config
- type Dialect
- func (dialect *Dialect) Read(reader io.Reader) (Config, error)
- func (dialect *Dialect) ReadFunc(reader io.Reader, fn func(sect, name string, valu interface{})) error
- func (dialect *Dialect) ReadTyped(reader io.Reader) (TypedConfig, error)
- func (dialect *Dialect) Write(writer io.Writer, conf Config) error
- func (dialect *Dialect) WriteTyped(writer io.Writer, conf TypedConfig) error
- type Section
- type TypedConfig
- type TypedSection
Constants ¶
This section is empty.
Variables ¶
var DefaultDialect = &Dialect{ AssignChars: "=:", CommentChars: ";#", ReadEmptyKeys: true, WriteEmptyKeys: false, Strict: false, }
DefaultDialect contains the default configuration dialect. It is compatible with Windows INI files.
Functions ¶
func WriteTyped ¶
func WriteTyped(writer io.Writer, conf TypedConfig) error
WriteTyped writes a typed configuration to the supplied writer using the default dialect.
Types ¶
type Config ¶
Config is used to store a configuration as string properties.
When using Get, Set, Delete to manipulate properties the property names follow the syntax SECTION.PROPNAME
type Dialect ¶
type Dialect struct { // AssignChars contains the characters used for property assignment. // The first character in AssignChars is the character used during // writing. AssignChars string // CommentChars contains the characters used for comments. CommentChars string // ReadEmptyKeys determines whether to read properties with missing values. // The properties so created will be interpretted as empty strings for Read // and boolean true for ReadTyped. ReadEmptyKeys bool // WriteEmptyKeys determines whether to write properties with missing values. // This is only important when writing boolean true properties with // WriteTyped; these will be written with missing values. WriteEmptyKeys bool // Strict determines whether parse errors should be reported. Strict bool }
Dialect is used to represent different dialects of configuration files.
func (*Dialect) ReadTyped ¶
func (dialect *Dialect) ReadTyped(reader io.Reader) (TypedConfig, error)
ReadTyped reads a typed configuration from the supplied reader.
func (*Dialect) WriteTyped ¶
func (dialect *Dialect) WriteTyped(writer io.Writer, conf TypedConfig) error
WriteTyped writes a typed configuration to the supplied writer.
type TypedConfig ¶
type TypedConfig map[string]TypedSection
TypedConfig is used to store a configuration as typed properties.
When using Get, Set, Delete to manipulate properties the property names follow the syntax SECTION.PROPNAME
func ReadTyped ¶
func ReadTyped(reader io.Reader) (TypedConfig, error)
ReadTyped reads a typed configuration from the supplied reader using the default dialect.
func (TypedConfig) Delete ¶
func (conf TypedConfig) Delete(k string)
Delete deletes a property from the configuration.
func (TypedConfig) Get ¶
func (conf TypedConfig) Get(k string) interface{}
Get gets a property from the configuration.
func (TypedConfig) Set ¶
func (conf TypedConfig) Set(k string, v interface{})
Set sets a property in the configuration.
type TypedSection ¶
type TypedSection map[string]interface{}
TypedSection is used to store a configuration section as typed properties.