config: github.com/revel/config Index | Files

package config

import "github.com/revel/config"

Index

Package Files

config.go context.go error.go option.go read.go section.go type.go write.go

Constants

const (
    // Default section name.
    DefaultSection = "DEFAULT"
    // Maximum allowed depth when recursively substituing variable names.
    DepthValues = 200

    DefaultComment       = "# "
    AlternativeComment   = "; "
    DefaultSeparator     = ":"
    AlternativeSeparator = "="
)

config constants

type Config Uses

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

Config is the representation of configuration settings.

func New Uses

func New(comment, separator string, preSpace, postSpace bool) *Config

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 `DefaultComment` or `AlternativeComment` separator: has to be `DefaultSeparator` or `AlternativeSeparator` preSpace: indicate if is inserted a space before of the separator postSpace: indicate if is added a space after of the separator

func NewDefault Uses

func NewDefault() *Config

NewDefault creates a configuration representation with values by default.

func Read Uses

func Read(fname string, comment, separator string, preSpace, postSpace bool) (*Config, error)

Read reads a configuration file and returns its representation. All arguments, except `fname`, are related to `New()`

func ReadDefault Uses

func ReadDefault(fname string) (*Config, error)

ReadDefault reads a configuration file and returns its representation. It uses values by default.

func (*Config) AddOption Uses

func (c *Config) AddOption(section string, option string, value string) bool

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 Uses

func (c *Config) AddSection(section string) bool

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 Uses

func (c *Config) Bool(section string, option string) (value bool, err error)

Bool has the same behaviour as String but converts the response to bool. See "boolString" for string values converted to bool.

func (*Config) Float Uses

func (c *Config) Float(section string, option string) (value float64, err error)

Float has the same behaviour as String but converts the response to float.

func (*Config) HasOption Uses

func (c *Config) HasOption(section string, option string) bool

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 Uses

func (c *Config) HasSection(section string) bool

HasSection checks if the configuration has the given section. (The default section always exists.)

func (*Config) Int Uses

func (c *Config) Int(section string, option string) (value int, err error)

Int has the same behaviour as String but converts the response to int.

func (*Config) Merge Uses

func (target *Config) Merge(source *Config)

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 Uses

func (c *Config) Options(section string) (options []string, err error)

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 Uses

func (c *Config) RawString(section string, option string) (value string, err error)

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 Uses

func (c *Config) RawStringDefault(option string) (value string, err error)

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 Uses

func (c *Config) RemoveOption(section string, option string) bool

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 Uses

func (c *Config) RemoveSection(section string) bool

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 Uses

func (c *Config) SectionOptions(section string) (options []string, err error)

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 Uses

func (c *Config) Sections() (sections []string)

Sections returns the list of sections in the configuration. (The default section always exists).

func (*Config) String Uses

func (c *Config) String(section string, option string) (value string, err error)

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 `DepthValues` number of iterations.

It returns an error if either the section or the option do not exist, or the unfolding cycled.

func (*Config) WriteFile Uses

func (c *Config) WriteFile(fname string, perm os.FileMode, header string) error

WriteFile saves the configuration representation to a file. The desired file permissions must be passed as in os.Open. The header is a string that is saved as a comment in the first line of the file.

type Context Uses

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

Context structure handles the parsing of app.conf It has a "preferred" section that is checked first for option queries. If the preferred section does not have the option, the DEFAULT section is checked fallback.

func LoadContext Uses

func LoadContext(confName string, confPaths []string) (*Context, error)

LoadContext loads the ini config from gives multiple conf paths

func NewContext Uses

func NewContext() *Context

NewContext creates a default section and returns config context

func (*Context) Bool Uses

func (c *Context) Bool(option string) (result, found bool)

Bool returns `bool` config value and if found returns true otherwise false

func (*Context) BoolDefault Uses

func (c *Context) BoolDefault(option string, dfault bool) bool

BoolDefault returns `bool` config value if found otherwise returns given default bool value

func (*Context) HasSection Uses

func (c *Context) HasSection(section string) bool

HasSection checks if the configuration has the given section. (The default section always exists.)

func (*Context) Int Uses

func (c *Context) Int(option string) (result int, found bool)

Int returns `int` config value and if found returns true otherwise false

func (*Context) IntDefault Uses

func (c *Context) IntDefault(option string, dfault int) int

IntDefault returns `int` config value if found otherwise returns given default int value

func (*Context) Options Uses

func (c *Context) Options(prefix string) []string

Options returns all configuration option keys. If a prefix is provided, then that is applied as a filter.

func (*Context) Raw Uses

func (c *Context) Raw() *Config

Raw returns raw config instance

func (*Context) SetOption Uses

func (c *Context) SetOption(name, value string)

SetOption sets the value for the given key

func (*Context) SetSection Uses

func (c *Context) SetSection(section string)

SetSection the section scope of ini config For e.g.: dev or prod

func (*Context) String Uses

func (c *Context) String(option string) (result string, found bool)

String returns `string` config value and if found returns true otherwise false

func (*Context) StringDefault Uses

func (c *Context) StringDefault(option, dfault string) string

StringDefault returns `string` config value if found otherwise returns given default string value

type OptionError Uses

type OptionError string

OptionError type string

func (OptionError) Error Uses

func (e OptionError) Error() string

type SectionError Uses

type SectionError string

SectionError type string

func (SectionError) Error Uses

func (e SectionError) Error() string

Package config imports 9 packages (graph) and is imported by 9 packages. Updated 2017-03-25. Refresh now. Tools for package owners.