config

package
v0.0.0-...-c67ada1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2019 License: MIT Imports: 16 Imported by: 5

Documentation

Overview

Package config provides configuration management for the KumuluzEE microservice framework.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bundle

type Bundle struct {
	Logger logm.Logm
	// contains filtered or unexported fields
}

Bundle is used for filling a user-defined struct with config values. Bundle should be initialized with config.NewBundle() function

func NewBundle

func NewBundle(prefixKey string, fields interface{}, options Options) Bundle

NewBundle fills the given fields struct with values from loaded configuration

type Options

type Options struct {
	// ConfigPath is a path to configuration file, including the configuration file name.
	// Passing an empty string will default to config/config.yaml
	ConfigPath string
	// Additional configuration source to connect to. Possible values are: "consul", "etcd"
	Extension string
	// Additional configuration source's namespace to use (i.e. path prefix). Setting this to a
	// non-empty value overwrites default namespace or namespace defined in configuration file
	ExtensionNamespace string
	// LogLevel can be used to limit the amount of logging output. Default log level is 0. Level 4
	// will only output Warnings and Errors, and level 5 will only output errors.
	// See package github.com/mc0239/logm for more details on logging and log levels.
	LogLevel int
}

Options struct is used when instantiating a new Util or Bundle.

type Util

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

Util is used for retrieving config values from available sources. Util should be initialized with config.NewUtil() function

func NewUtil

func NewUtil(options Options) Util

NewUtil instantiates a new Util with given options

func (Util) Get

func (c Util) Get(key string) interface{}

Get returns the value for a given key, stored in configuration. Configuration sources are checked by their ordinal numbers, and value is returned from first configuration source it was found in.

func (Util) GetBool

func (c Util) GetBool(key string) (value bool, ok bool)

GetBool is a helper method that calls Util.Get() internally and type asserts the value to bool before returning it. If value is not found in any configuration source or the value could not be type asserted to bool, a false is returned with ok equal to false.

func (Util) GetFloat

func (c Util) GetFloat(key string) (value float64, ok bool)

GetFloat is a helper method that calls Util.Get() internally and type asserts the value to float64 before returning it. If value is not found in any configuration source or the value could not be type asserted to float64, a zero is returned with ok equal to false.

func (Util) GetInt

func (c Util) GetInt(key string) (value int, ok bool)

GetInt is a helper method that calls Util.Get() internally and type asserts the value to int before returning it. If value is not found in any configuration source or the value could not be type asserted to int, a zero is returned with ok equal to false.

func (Util) GetString

func (c Util) GetString(key string) (value string, ok bool)

GetString is a helper method that calls Util.Get() internally and type asserts the value to string before returning it. If value is not found in any configuration source or the value could not be type asserted to string, an empty string is returned with ok equal to false.

func (Util) Subscribe

func (c Util) Subscribe(key string, callback func(key string, value string))

Subscribe creates a watch on a given configuration key. Note that watch will be enabled on an extension configuration source, if one has been defined when Util was created. When value in configuration updates, callback is fired with the key and the new value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL