config

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2018 License: MIT Imports: 6 Imported by: 13

Documentation

Overview

Package config is nice and handy layer built around `forge` config syntax; which is similar to HOCON syntax. Internally `aah/config` uses `forge` syntax developed by `https://github.com/brettlangdon`.

aah framework is powered with `aahframework.org/config` library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Config handles the configuration values and enables environment profile's, merge, etc. Also it provide nice and handly methods for accessing config values. Internally `aah config` uses `forge syntax` developed by `https://github.com/brettlangdon`.

func LoadFile

func LoadFile(filename string) (*Config, error)

LoadFile loads the configuration from given config file.

func LoadFiles

func LoadFiles(files ...string) (*Config, error)

LoadFiles loads the configuration from given config files. It does merging of configuration in the order they are given.

func NewEmpty

func NewEmpty() *Config

NewEmpty method returns aah empty config instance.

func ParseString

func ParseString(cfg string) (*Config, error)

ParseString parses the configuration values from string

func (*Config) Bool

func (c *Config) Bool(key string) (bool, bool)

Bool gets the `bool` value for the given key from the configuration.

func (*Config) BoolDefault

func (c *Config) BoolDefault(key string, defaultValue bool) bool

BoolDefault gets the `bool` value for the given key from the configuration. If key does not exists it returns default value.

func (*Config) ClearProfile

func (c *Config) ClearProfile()

ClearProfile clears currently active configuration `Profile`

func (*Config) Float32

func (c *Config) Float32(key string) (float32, bool)

Float32 gets the `float32` value for the given key from the configuration.

func (*Config) Float32Default

func (c *Config) Float32Default(key string, defaultValue float32) float32

Float32Default gets the `float32` value for the given key from the configuration. If key does not exists it returns default value.

func (*Config) Float64

func (c *Config) Float64(key string) (float64, bool)

Float64 gets the `float64` value for the given key from the configuration.

func (*Config) Get

func (c *Config) Get(key string) (interface{}, bool)

Get gets the value from configuration returns as `interface{}`. First it tries to get value within enabled profile otherwise it tries without profile

func (*Config) GetSubConfig

func (c *Config) GetSubConfig(key string) (*Config, bool)

GetSubConfig create new sub config from the given key path. Only `Section` type can be created as sub config. Profile value is not propagated to sub config.

func (*Config) HasProfile

func (c *Config) HasProfile(profile string) bool

HasProfile checks given configuration profile is exists or not

func (*Config) Int

func (c *Config) Int(key string) (int, bool)

Int gets the `int` value for the given key from the configuration.

func (*Config) Int64

func (c *Config) Int64(key string) (int64, bool)

Int64 gets the `int64` value for the given key from the configuration.

func (*Config) Int64List

func (c *Config) Int64List(key string) ([]int64, bool)

Int64List method returns the int64 slice value for the given key.

Eaxmple:-

Config:
	...
	int64_list = [100000001, 100000002, 100000003, 100000004, 100000005]
	...

Accessing Values:
	values, found := cfg.Int64List("excludes")
	fmt.Println("Found:", found)
	fmt.Println("Values:", values)

Output:
	Found: true
	Values: [100000001, 100000002, 100000003, 100000004, 100000005]

func (*Config) IntDefault

func (c *Config) IntDefault(key string, defaultValue int) int

IntDefault gets the `int` value for the given key from the configuration. If key does not exists it returns default value.

func (*Config) IntList

func (c *Config) IntList(key string) ([]int, bool)

IntList method returns the int slice value for the given key.

Eaxmple:-

Config:
	...
	int_list = [10, 20, 30, 40, 50]
	...

Accessing Values:
	values, found := cfg.IntList("int_list")
	fmt.Println("Found:", found)
	fmt.Println("Values:", values)

Output:
	Found: true
	Values: [10, 20, 30, 40, 50]

func (*Config) IsExists

func (c *Config) IsExists(key string) bool

IsExists returns true if given is exists in the config otherwise returns false

func (*Config) IsProfileEnabled

func (c *Config) IsProfileEnabled() bool

IsProfileEnabled returns true of profile enabled otherwise false

func (*Config) Keys

func (c *Config) Keys() []string

Keys returns all the key names at current level

func (*Config) KeysByPath

func (c *Config) KeysByPath(path string) []string

KeysByPath is similar to `Config.Keys()`, however it returns key names for given key path.

func (*Config) Merge

func (c *Config) Merge(source *Config) error

Merge merges the given section to current section. Settings from source section overwites the values in the current section

NOTE: It does not affect physical config file.

func (*Config) Merge2Section

func (c *Config) Merge2Section(key string, source *Config) error

Merge2Section method allows to merge config into existing config section. Source config becomes child of target section config.

NOTE: It does not affect physical config file.

func (*Config) Profile

func (c *Config) Profile() string

Profile returns current active profile

func (*Config) SetBool

func (c *Config) SetBool(key string, value bool)

SetBool sets the given value bool for config key First it tries to get value within enabled profile otherwise it tries without profile

func (*Config) SetFloat32

func (c *Config) SetFloat32(key string, value float32)

SetFloat32 sets the given value float32 for config key First it tries to get value within enabled profile otherwise it tries without profile

func (*Config) SetFloat64

func (c *Config) SetFloat64(key string, value float64)

SetFloat64 sets the given value float64 for config key First it tries to get value within enabled profile otherwise it tries without profile

func (*Config) SetInt

func (c *Config) SetInt(key string, value int)

SetInt sets the given value int for config key First it tries to get value within enabled profile otherwise it tries without profile

func (*Config) SetInt64

func (c *Config) SetInt64(key string, value int64)

SetInt64 sets the given value int64 for config key First it tries to get value within enabled profile otherwise it tries without profile

func (*Config) SetProfile

func (c *Config) SetProfile(profile string) error

SetProfile actives the configuarion profile if found otherwise returns error

func (*Config) SetString

func (c *Config) SetString(key string, value string)

SetString sets the given value string for config key First it tries to get value within enabled profile otherwise it tries without profile

func (*Config) String

func (c *Config) String(key string) (string, bool)

String gets the `string` value for the given key from the configuration.

func (*Config) StringDefault

func (c *Config) StringDefault(key, defaultValue string) string

StringDefault gets the `string` value for the given key from the configuration. If key does not exists it returns default value.

func (*Config) StringList

func (c *Config) StringList(key string) ([]string, bool)

StringList method returns the string slice value for the given key.

Eaxmple:-

Config:
	...
	excludes = ["*_test.go", ".*", "*.bak", "*.tmp", "vendor"]
	...

Accessing Values:
	values, found := cfg.StringList("excludes")
	fmt.Println("Found:", found)
	fmt.Println("Values:", strings.Join(values, ", "))

Output:
	Found: true
	Values: *_test.go, .*, *.bak, *.tmp, vendor

func (*Config) ToJSON

func (c *Config) ToJSON() string

ToJSON method returns the configuration values as JSON string.

Jump to

Keyboard shortcuts

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