import "github.com/revel/config"
config.go context.go error.go option.go read.go section.go type.go write.go
const ( // Default section name. DefaultSection = "DEFAULT" // Maximum allowed depth when recursively substituing variable names. DepthValues = 200 DefaultComment = "# " AlternativeComment = "; " DefaultSeparator = ":" AlternativeSeparator = "=" )
config constants
type Config struct {
// contains filtered or unexported fields
}
Config is the representation of configuration settings.
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
NewDefault creates a configuration representation with values by default.
Read reads a configuration file and returns its representation. All arguments, except `fname`, are related to `New()`
ReadDefault reads a configuration file and returns its representation. It uses values by default.
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.
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.
Bool has the same behaviour as String but converts the response to bool. See "boolString" for string values converted to bool.
Float has the same behaviour as String but converts the response to float.
HasOption checks if the configuration has the given option in the section. It returns false if either the option or section do not exist.
HasSection checks if the configuration has the given section. (The default section always exists.)
Int has the same behaviour as String but converts the response to int.
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).
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.
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.
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.
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.
RemoveSection removes a section from the configuration. It returns true if the section was removed, and false if section did not exist.
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.
Sections returns the list of sections in the configuration. (The default section always exists).
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.
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 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.
LoadContext loads the ini config from gives multiple conf paths
NewContext creates a default section and returns config context
Bool returns `bool` config value and if found returns true otherwise false
BoolDefault returns `bool` config value if found otherwise returns given default bool value
HasSection checks if the configuration has the given section. (The default section always exists.)
Int returns `int` config value and if found returns true otherwise false
IntDefault returns `int` config value if found otherwise returns given default int value
Options returns all configuration option keys. If a prefix is provided, then that is applied as a filter.
Raw returns raw config instance
SetOption sets the value for the given key
SetSection the section scope of ini config For e.g.: dev or prod
String returns `string` config value and if found returns true otherwise false
StringDefault returns `string` config value if found otherwise returns given default string value
OptionError type string
func (e OptionError) Error() string
SectionError type string
func (e SectionError) Error() string
Package config imports 9 packages (graph) and is imported by 78 packages. Updated 2018-10-30. Refresh now. Tools for package owners.