Documentation ¶
Index ¶
- Constants
- Variables
- func AddOption(section string, option string, value string) bool
- func AddSection(section string) bool
- func Bool(section string, option string) (value bool, err error)
- func Float(section string, option string) (value float64, err error)
- func HasOption(section string, option string) bool
- func HasSection(section string) bool
- func Int(section string, option string) (value int, err error)
- func Merge(source *Config)
- func Options(section string) (options []string, err error)
- func RawString(section string, option string) (value string, err error)
- func RawStringDefault(option string) (value string, err error)
- func RemoveOption(section string, option string) bool
- func RemoveSection(section string) bool
- func SectionOptions(section string) (options []string, err error)
- func Sections() (sections []string)
- func String(section string, option string) (value string, err error)
- func WriteFile(fname string, perm os.FileMode, header string) error
- type Config
- func InitConfig(fname string, base_section string) (cfg *Config, err error)
- func New(comment, separator string, preSpace, postSpace bool) *Config
- func NewDefault() *Config
- func Read(fname string, comment, separator string, preSpace, postSpace bool) (*Config, error)
- func ReadDefault(fname string) (*Config, error)
- func (c *Config) AddOption(section string, option string, value string) bool
- func (c *Config) AddSection(section string) bool
- func (c *Config) Bool(section string, option string) (value bool, err error)
- func (c *Config) DynamicString(str string) (value string, err error)
- func (c *Config) Float(section string, option string) (value float64, err error)
- func (c *Config) HasOption(section string, option string) bool
- func (c *Config) HasSection(section string) bool
- func (c *Config) Int(section string, option string) (value int, err error)
- func (target *Config) Merge(source *Config)
- func (c *Config) Options(section string) (options []string, err error)
- func (c *Config) RawString(section string, option string) (value string, err error)
- func (c *Config) RawStringDefault(option string) (value string, err error)
- func (c *Config) RemoveOption(section string, option string) bool
- func (c *Config) RemoveSection(section string) bool
- func (c *Config) SectionOptions(section string) (options []string, err error)
- func (c *Config) Sections() (sections []string)
- func (c *Config) String(section string, option string) (value string, err error)
- func (c *Config) WriteFile(fname string, perm os.FileMode, header string) error
- type OptionError
- type SectionError
Constants ¶
const ( // Default section name. DEFAULT_SECTION = "DEFAULT" DEFAULT_COMMENT = "# " ALTERNATIVE_COMMENT = "; " DEFAULT_SEPARATOR = "=" ALTERNATIVE_SEPARATOR = ":" )
Variables ¶
var (
BASE_SECTION string
)
Functions ¶
func AddSection ¶
func HasSection ¶
func RawStringDefault ¶
func RemoveOption ¶
func RemoveSection ¶
func SectionOptions ¶
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config is the representation of configuration settings.
func InitConfig ¶
初始化全局配置文件
func New ¶
New creates an empty configuration representation. This representation can be filled with AddSection and AddOption and then saved to a file using WriteFile.
== Arguments
comment: has to be `DEFAULT_COMMENT` or `ALTERNATIVE_COMMENT` separator: has to be `DEFAULT_SEPARATOR` or `ALTERNATIVE_SEPARATOR` preSpace: indicate if is inserted a space before of the separator postSpace: indicate if is added a space after of the separator
func NewDefault ¶
func NewDefault() *Config
NewDefault creates a configuration representation with values by default.
func Read ¶
Read reads a configuration file and returns its representation. All arguments, except `fname`, are related to `New()`
func ReadDefault ¶
ReadDefault reads a configuration file and returns its representation. It uses values by default.
func (*Config) AddOption ¶
AddOption adds a new option and value to the configuration.
If the section is nil then uses the section by default; if it does not exist, it is created in advance.
It returns true if the option and value were inserted, and false if the value was overwritten.
func (*Config) AddSection ¶
AddSection adds a new section to the configuration.
If the section is nil then uses the section by default which it's already created.
It returns true if the new section was inserted, and false if the section already existed.
func (*Config) Bool ¶
Bool has the same behaviour as String but converts the response to bool. See "boolString" for string values converted to bool.
func (*Config) DynamicString ¶
String gets the string value for the given dynamic string. e.g. %(host)s example;${host} example
func (*Config) HasOption ¶
HasOption checks if the configuration has the given option in the section. It returns false if either the option or section do not exist.
func (*Config) HasSection ¶
HasSection checks if the configuration has the given section. (The default section always exists.)
func (*Config) Merge ¶
Merge merges the given configuration "source" with this one ("target").
Merging means that any option (under any section) from source that is not in target will be copied into target. When the target already has an option with the same name and section then it is overwritten (i.o.w. the source wins).
func (*Config) Options ¶
Options returns the list of options available in the given section. It returns an error if the section does not exist and an empty list if the section is empty. Options within the default section are also included.
func (*Config) RawString ¶
RawString gets the (raw) string value for the given option in the section. The raw string value is not subjected to unfolding, which was illustrated in the beginning of this documentation.
It returns an error if either the section or the option do not exist.
func (*Config) RawStringDefault ¶
RawStringDefault gets the (raw) string value for the given option from the DEFAULT section.
It returns an error if the option does not exist in the DEFAULT section.
func (*Config) RemoveOption ¶
RemoveOption removes a option and value from the configuration. It returns true if the option and value were removed, and false otherwise, including if the section did not exist.
func (*Config) RemoveSection ¶
RemoveSection removes a section from the configuration. It returns true if the section was removed, and false if section did not exist.
func (*Config) SectionOptions ¶
SectionOptions returns only the list of options available in the given section. Unlike Options, SectionOptions doesn't return options in default section. It returns an error if the section doesn't exist.
func (*Config) Sections ¶
Sections returns the list of sections in the configuration. (The default section always exists).
func (*Config) String ¶
String gets the string value for the given option in the section. If the value needs to be unfolded (see e.g. %(host)s example in the beginning of this documentation), then String does this unfolding automatically, up to _DEPTH_VALUES number of iterations.
It returns an error if either the section or the option do not exist, or the unfolding cycled.
type OptionError ¶
type OptionError string
func (OptionError) Error ¶
func (e OptionError) Error() string
type SectionError ¶
type SectionError string
func (SectionError) Error ¶
func (e SectionError) Error() string