Documentation ¶
Index ¶
- Constants
- type Comment
- type Config
- func (c *Config) AddOption(section string, subsection string, key string, value string) *Config
- func (c *Config) HasSection(name string) bool
- func (c *Config) HashAlgo() string
- func (c *Config) RemoveSection(name string) *Config
- func (c *Config) RemoveSubsection(section string, subsection string) *Config
- func (c *Config) Section(name string) *Section
- func (c *Config) SetOption(section string, subsection string, key string, value string) *Config
- type Decoder
- type Include
- type Includes
- type Option
- type Options
- type Section
- func (s *Section) AddOption(key string, value string) *Section
- func (s *Section) HasOption(key string) bool
- func (s *Section) HasSubsection(name string) bool
- func (s *Section) IsName(name string) bool
- func (s *Section) Option(key string) string
- func (s *Section) OptionAll(key string) []string
- func (s *Section) RemoveOption(key string) *Section
- func (s *Section) RemoveSubsection(name string) *Section
- func (s *Section) SetOption(key string, value string) *Section
- func (s *Section) Subsection(name string) *Subsection
- type Sections
- type Subsection
- func (s *Subsection) AddOption(key string, value string) *Subsection
- func (s *Subsection) HasOption(key string) bool
- func (s *Subsection) IsName(name string) bool
- func (s *Subsection) Option(key string) string
- func (s *Subsection) OptionAll(key string) []string
- func (s *Subsection) RemoveOption(key string) *Subsection
- func (s *Subsection) SetOption(key string, value ...string) *Subsection
- type Subsections
Constants ¶
const ( // NoSubsection token is passed to Config.Section and Config.SetSection to // represent the absence of a section. NoSubsection = "" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
Config contains all the sections, comments and includes from a config file.
func BareDecode ¶
func (*Config) AddOption ¶
AddOption adds an option to a given section and subsection. Use the NoSubsection constant for the subsection argument if no subsection is wanted.
func (*Config) HasSection ¶
HasSection checks if the Config has a section with the specified name.
func (*Config) RemoveSection ¶
RemoveSection removes a section from a config file.
func (*Config) RemoveSubsection ¶
RemoveSubsection remove a subsection from a config file.
type Decoder ¶
A Decoder reads and decodes config files from an input stream.
func NewDecoder ¶
NewDecoder returns a new decoder that reads from r.
type Option ¶
type Option struct { // Key preserving original caseness. // Use IsKey instead to compare key regardless of caseness. Key string // Original value as string, could be not normalized. Value string }
Option defines a key/value entity in a config file.
type Options ¶
type Options []*Option
func (Options) Get ¶
Get gets the value for the given key if set, otherwise it returns the empty string.
Note that there is no difference ¶
This matches git behaviour since git v1.8.1-rc1, if there are multiple definitions of a key, the last one wins.
See: http://article.gmane.org/gmane.linux.kernel/1407184
In order to get all possible values for the same key, use GetAll.
type Section ¶
type Section struct { Name string Options Options Subsections Subsections }
Section is the representation of a section inside git configuration files. Each Section contains Options that are used by both the Git plumbing and the porcelains. Sections can be further divided into subsections. To begin a subsection put its name in double quotes, separated by space from the section name, in the section header, like in the example below:
[section "subsection"]
All the other lines (and the remainder of the line after the section header) are recognized as option variables, in the form "name = value" (or just name, which is a short-hand to say that the variable is the boolean "true"). The variable names are case-insensitive, allow only alphanumeric characters and -, and must start with an alphabetic character:
[section "subsection1"] option1 = value1 option2 [section "subsection2"] option3 = value2
func (*Section) AddOption ¶
AddOption adds a new Option to the Section. The updated Section is returned.
func (*Section) HasSubsection ¶
HasSubsection checks if the Section has a Subsection with the specified name.
func (*Section) IsName ¶
IsName checks if the name provided is equals to the Section name, case insensitive.
func (*Section) Option ¶
Option returns the value for the specified key. Empty string is returned if key does not exists.
func (*Section) OptionAll ¶
OptionAll returns all possible values for an option with the specified key. If the option does not exists, an empty slice will be returned.
func (*Section) RemoveOption ¶
Remove an option with the specified key. The updated Section is returned.
func (*Section) RemoveSubsection ¶
RemoveSubsection removes a subsection from a Section.
func (*Section) SetOption ¶
SetOption adds a new Option to the Section. If the option already exists, is replaced. The updated Section is returned.
func (*Section) Subsection ¶
func (s *Section) Subsection(name string) *Subsection
Subsection returns a Subsection from the specified Section. If the Subsection does not exists, new one is created and added to Section.
type Subsection ¶
func (*Subsection) AddOption ¶
func (s *Subsection) AddOption(key string, value string) *Subsection
AddOption adds a new Option to the Subsection. The updated Subsection is returned.
func (*Subsection) HasOption ¶
func (s *Subsection) HasOption(key string) bool
HasOption checks if the Subsection has an Option with the given key.
func (*Subsection) IsName ¶
func (s *Subsection) IsName(name string) bool
IsName checks if the name of the subsection is exactly the specified name.
func (*Subsection) Option ¶
func (s *Subsection) Option(key string) string
Option returns an option with the specified key. If the option does not exists, empty spring will be returned.
func (*Subsection) OptionAll ¶
func (s *Subsection) OptionAll(key string) []string
OptionAll returns all possible values for an option with the specified key. If the option does not exists, an empty slice will be returned.
func (*Subsection) RemoveOption ¶
func (s *Subsection) RemoveOption(key string) *Subsection
RemoveOption removes the option with the specified key. The updated Subsection is returned.
func (*Subsection) SetOption ¶
func (s *Subsection) SetOption(key string, value ...string) *Subsection
SetOption adds a new Option to the Subsection. If the option already exists, is replaced. The updated Subsection is returned.
type Subsections ¶
type Subsections []*Subsection
func (Subsections) GoString ¶
func (s Subsections) GoString() string