Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEmptyItem reports that the config item content is empty. // This error is returned when trying to bind an empty configuration item to any object. ErrEmptyItem = errors.New("configurator: empty item") // ErrNotFound indicates that the configuration target was not found. // When a configuration target cannot be loaded in all loaders, this error will be returned. ErrNotFound = errors.New("configurator: not found") )
Functions ¶
This section is empty.
Types ¶
type Configurator ¶ added in v1.2.0
type Configurator interface { // Use registers a custom configuration loader. // The last registered configuration loader will have the highest priority. Use(Loader) Configurator // AddFile adds one or more config files to the current loader. // The given parameter need to comply with the search rules supported // by filepath.Glob. // This method comes from the built-in configuration file loader. AddFile(string) error // Load loads the given config target. // If the given config target does not exist, ErrNotFound is returned. // We will give priority to the custom loader. If there is no available config loader // or all registered config loaders cannot load the config target (the semantic target // does not exist), it will be automatically delegated to the built-in config file loader. Load(string) (Item, error) // LoadJSON loads the given config target and binds it to the given object as json. LoadJSON(string, interface{}) error // LoadXML loads the given config target and binds it to the given object as xml. LoadXML(string, interface{}) error // LoadTOML loads the given config target and binds it to the given object as toml. LoadTOML(string, interface{}) error // LoadYAML loads the given config target and binds it to the given object as yaml. LoadYAML(string, interface{}) error }
Configurator defines the configuration manager.
type FileItem ¶ added in v1.2.0
type FileItem interface { Item // Path returns the config file absolute path. Path() string // Base returns the config file base name. Base() string // Name returns the config file name (without extension name). Name() string }
FileItem interface defines the config file item.
func NewFileItem ¶ added in v1.2.0
NewFileItem returns the config file item created from the given file path. An error is returned only if a failure occurs to read the contents of the given config file.
type FileLoader ¶
type FileLoader interface { Loader // AddFile adds one or more config files to the current loader. // The given parameter need to comply with the search rules supported // by filepath.Glob. AddFile(string) error // MustAddFile adds one or more config files to the current loader. // This method is very similar to AddFile, the only difference is that it panics // when the add fails. MustAddFile(pattern string) FileLoader }
FileLoader interface defines the config file loader.
func NewFileLoader ¶
func NewFileLoader() FileLoader
NewFileLoader creates and returns a config file loader instance.
type Item ¶ added in v1.2.0
type Item interface { // IsEmpty determines whether the current config item content is empty. IsEmpty() bool // Len returns the current config item content length. Len() int // Bytes returns the current config item content bytes. Bytes() []byte // Bytes returns the current config item content string. String() string // Bytes returns the current config item content reader. Reader() io.Reader // JSON binds the current config item to the given object as json format. // If the current configuration item is empty, ErrEmptyItem will be returned. JSON(interface{}) error // XML binds the current config item to the given object as xml format. // If the current configuration item is empty, ErrEmptyItem will be returned. XML(interface{}) error // TOML binds the current config item to the given object as toml format. // If the current configuration item is empty, ErrEmptyItem will be returned. TOML(interface{}) error // YAML binds the current config item to the given object as yaml format. // If the current configuration item is empty, ErrEmptyItem will be returned. YAML(interface{}) error }
Item interface defines the config item.
func NewItemFromBytes ¶ added in v1.2.0
NewItemFromBytes creates and returns a config item from the given bytes.
func NewItemFromReader ¶ added in v1.2.0
NewItemFromReader creates and returns a config item from the given reader.
func NewItemFromString ¶ added in v1.2.0
NewItemFromString creates and returns a config item from the given string.
type Loader ¶
type Loader interface { // Load loads the given config target. // If this method returns a non-nil error, the entire configuration search and // loading process will be terminated immediately. If the returned Item is nil, // the next loader in the queue will be automatically run. Load(string) (Item, error) }
Loader interface defines the config target loader.