config.v0: aahframework.org/config.v0 Index | Files

package config

import "aahframework.org/config.v0"

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

Package Files

config.go version.go

Variables

var Version = "0.5.0"

Version no. of aahframework.org/config library

type Config Uses

type Config struct {
    // 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 Uses

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

LoadFile loads the configuration from given config file.

func LoadFiles Uses

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 Uses

func NewEmpty() *Config

NewEmpty method returns aah empty config instance.

func ParseString Uses

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

ParseString parses the configuration values from string

func VFSLoadFile Uses

func VFSLoadFile(fs *vfs.VFS, file string) (*Config, error)

VFSLoadFile loads the configuration from given vfs and config file.

func VFSLoadFiles Uses

func VFSLoadFiles(fs *vfs.VFS, files ...string) (*Config, error)

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

func (*Config) Bool Uses

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

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

func (*Config) BoolDefault Uses

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 Uses

func (c *Config) ClearProfile()

ClearProfile clears currently active configuration `Profile`

func (*Config) Float32 Uses

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

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

func (*Config) Float32Default Uses

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 Uses

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

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

func (*Config) Get Uses

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 Uses

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 Uses

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

HasProfile checks given configuration profile is exists or not

func (*Config) Int Uses

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

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

func (*Config) Int64 Uses

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

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

func (*Config) Int64List Uses

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 Uses

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 Uses

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 Uses

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

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

func (*Config) IsProfileEnabled Uses

func (c *Config) IsProfileEnabled() bool

IsProfileEnabled returns true of profile enabled otherwise false

func (*Config) Keys Uses

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

Keys returns all the key names at current level

func (*Config) KeysByPath Uses

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 Uses

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

func (*Config) Profile Uses

func (c *Config) Profile() string

Profile returns current active profile

func (*Config) SetBool Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

SetProfile actives the configuarion profile if found otherwise returns error

func (*Config) SetString Uses

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 Uses

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

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

func (*Config) StringDefault Uses

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 Uses

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 Uses

func (c *Config) ToJSON() string

ToJSON method returns the configuration values as JSON string.

Package config imports 5 packages (graph) and is imported by 21 packages. Updated 2018-06-23. Refresh now. Tools for package owners.