Documentation ¶
Overview ¶
Package config provides a configuration management library for Go applications.
Index ¶
- func GetEnvAsBool(key string, defaultVal bool) (bool, error)
- func GetEnvAsDecimal(key string, defaultVal float64) (float64, error)
- func GetEnvAsInt(key string, defaultVal int) (int, error)
- func GetEnvAsInt64(key string, defaultVal int64) (int64, error)
- func GetEnvAsString(key, defaultVal string) string
- type Attributes
- type Configuration
- type MapAttributes
- func (m *MapAttributes) AsMap() map[string]any
- func (m *MapAttributes) Get(k string) any
- func (m *MapAttributes) GetAsArray(k string) []any
- func (m *MapAttributes) GetAsBool(k string) bool
- func (m *MapAttributes) GetAsBytes(k string) []byte
- func (m *MapAttributes) GetAsFloat(k string) float64
- func (m *MapAttributes) GetAsInt(k string) int
- func (m *MapAttributes) GetAsMap(k string) map[string]any
- func (m *MapAttributes) GetAsString(k string) string
- func (m *MapAttributes) IsThreadSafe() bool
- func (m *MapAttributes) Keys() []string
- func (m *MapAttributes) Merge(other Attributes)
- func (m *MapAttributes) Remove(k string)
- func (m *MapAttributes) Set(k string, v any)
- func (m *MapAttributes) ThreadSafe(ts bool)
- type Properties
- func (p *Properties) Get(k, d string) string
- func (p *Properties) GetAsBool(k string, defaultVal bool) (bool, error)
- func (p *Properties) GetAsDecimal(k string, defaultVal float64) (float64, error)
- func (p *Properties) GetAsInt(k string, defaultVal int) (int, error)
- func (p *Properties) GetAsInt64(k string, defaultVal int64) (int64, error)
- func (p *Properties) Load(r io.Reader) error
- func (p *Properties) Put(k, v string) string
- func (p *Properties) PutBool(k string, v bool) (bool, error)
- func (p *Properties) PutDecimal(k string, v float64) (float64, error)
- func (p *Properties) PutInt(k string, v int) (int, error)
- func (p *Properties) PutInt64(k string, v int64) (int64, error)
- func (p *Properties) Save(w io.Writer) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetEnvAsBool ¶
GetEnvAsBool function will fetch the val from environment variable and convert that to an GetEnvAsBool. If the value is absent then it will return defaultVal supplied. Valid boolean vals are 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False.
func GetEnvAsDecimal ¶
GetEnvAsDecimal function will fetch the val from environment variable and convert that to an float64. If the value is absent then it will return defaultVal supplied.
func GetEnvAsInt ¶
GetEnvAsInt function will fetch the val from environment variable and convert that to an integer. If the value is absent then it will return defaultVal supplied.
func GetEnvAsInt64 ¶
GetEnvAsInt64 function will fetch the val from environment variable and convert that to an integer of 64 bit. If the value is absent then it will return defaultVal supplied.
func GetEnvAsString ¶
GetEnvAsString function will fetch the val from environment variable. If the value is absent then it will return defaultVal supplied.
Types ¶
type Attributes ¶
type Attributes interface { // Set adds a new attribute to the message Set(k string, v any) // Get returns the value of the attribute Get(k string) any // GetAsString returns the value of the attribute as a string GetAsString(k string) string // GetAsInt returns the value of the attribute as an int GetAsInt(k string) int // GetAsFloat returns the value of the attribute as a float GetAsFloat(k string) float64 // GetAsBool returns the value of the attribute as a bool GetAsBool(k string) bool // GetAsBytes returns the value of the attribute as a byte array GetAsBytes(k string) []byte // GetAsArray returns the value of the attribute as an array GetAsArray(k string) []any // GetAsMap returns the value of the attribute as a map GetAsMap(k string) map[string]any // Remove removes the attribute from the message Remove(k string) // Keys returns the keys of the attributes Keys() []string // AsMap returns the attributes as a map AsMap() map[string]any // ThreadSafe makes the attributes thread safe ThreadSafe(bool) // IsThreadSafe returns true if the attributes are thread safe IsThreadSafe() bool // Merge merges this attribute with another attributes Merge(m Attributes) }
Interface Attirbutes is the interface that represents the attributes of a message
type Configuration ¶
type Configuration interface { //Load a reader from Reader Load(r io.Reader) error //Save to a writer Save(w io.Writer) error //Get returns configuration value as string identified by the key //If the value is absent then it will return defaultVal supplied. Get(k, defaultVal string) string //GetAsInt returns the config value as int64 identified by the key //If the value is absent then it will return defaultVal supplied. //This may throw an error if a non Int value is present for the key GetAsInt(k string, defaultVal int) (int, error) //GetAsInt64 returns the config value as int64 identified by the key //If the value is absent then it will return defaultVal supplied. //This may throw an error if a non int64 value is present for the key GetAsInt64(k string, defaultVal int64) (int64, error) //GetAsBool returns the config value as bool identified by the key //If the value is absent then it will return defaultVal supplied. //This may throw an error if a non bool value is present for the key GetAsBool(k string, defaultVal bool) (bool, error) //GetAsDecimal returns the config value as decimal float64 identified by the key //If the value is absent then it will return defaultVal supplied. //This may throw an error if a non float64 value is present for the key GetAsDecimal(k string, defaultVal float64) (float64, error) //Put returns configuration value as string identified by the key //If the value is absent then it will return defaultVal supplied. Put(k, v string) string //PutInt returns the config value as int64 identified by the key //If the value is absent then it will return defaultVal supplied. //This may throw an error if a non Int value is present for the key PutInt(k string, v int) (int, error) //PutInt64 returns the config value as int64 identified by the key //If the value is absent then it will return defaultVal supplied. //This may throw an error if a non int64 value is present for the key PutInt64(k string, v int64) (int64, error) //PutBool returns the config value as bool identified by the key //If the value is absent then it will return defaultVal supplied. //This may throw an error if a non bool value is present for the key PutBool(k string, v bool) (bool, error) //PutDecimal returns the config value as decimal float64 identified by the key //If the value is absent then it will return defaultVal supplied. //This may throw an error if a non float64 value is present for the key PutDecimal(k string, v float64) (float64, error) }
type MapAttributes ¶
type MapAttributes struct {
// contains filtered or unexported fields
}
func NewMapAttributes ¶
func NewMapAttributes() *MapAttributes
NewMapAttributes creates a new MapAttributes By default the attributes are thread safe To make them thread safe call the MakeThreadSafe() method
func (*MapAttributes) AsMap ¶
func (m *MapAttributes) AsMap() map[string]any
AsMap returns the attributes as a map. This is an expensive function as it creates a new map and copies all the attributes to it
func (*MapAttributes) Get ¶
func (m *MapAttributes) Get(k string) any
Get returns the value of the attribute
func (*MapAttributes) GetAsArray ¶
func (m *MapAttributes) GetAsArray(k string) []any
GetAsArray returns the value of the attribute as an array if first checks if the attribute is an array, if not it tries to convert it to an array if it fails it returns nil
func (*MapAttributes) GetAsBool ¶
func (m *MapAttributes) GetAsBool(k string) bool
GetAsBool returns the value of the attribute as a bool if first checks if the attribute is a bool, if not it tries to convert it to a bool if it fails it returns false
func (*MapAttributes) GetAsBytes ¶
func (m *MapAttributes) GetAsBytes(k string) []byte
GetAsBytes returns the value of the attribute as a byte array if first checks if the attribute is a byte array, if not it tries to convert it to a byte array if it fails it returns nil
func (*MapAttributes) GetAsFloat ¶
func (m *MapAttributes) GetAsFloat(k string) float64
GetAsFloat returns the value of the attribute as a float if first checks if the attribute is a float, if not it tries to convert it to a float if it fails it returns 0
func (*MapAttributes) GetAsInt ¶
func (m *MapAttributes) GetAsInt(k string) int
GetAsInt returns the value of the attribute as an int if first checks if the attribute is an int, if not it tries to convert it to an int if it fails it returns 0
func (*MapAttributes) GetAsMap ¶
func (m *MapAttributes) GetAsMap(k string) map[string]any
GetAsMap returns the value of the attribute as a map if first checks if the attribute is a map, if not it tries to convert it to a map if it fails it returns nil
func (*MapAttributes) GetAsString ¶
func (m *MapAttributes) GetAsString(k string) string
GetAsString returns the value of the attribute as a string if first checks if the attribute is a string, if not it tries to convert it to a string if it fails it returns an empty string
func (*MapAttributes) IsThreadSafe ¶
func (m *MapAttributes) IsThreadSafe() bool
IsThreadSafe returns true if the attributes are thread safe
func (*MapAttributes) Keys ¶
func (m *MapAttributes) Keys() []string
Keys returns the keys of the attributes
func (*MapAttributes) Merge ¶
func (m *MapAttributes) Merge(other Attributes)
Merge merges this attributes with another attributes
func (*MapAttributes) Remove ¶
func (m *MapAttributes) Remove(k string)
Remove removes the attribute from the message
func (*MapAttributes) Set ¶
func (m *MapAttributes) Set(k string, v any)
Set adds a new attribute to the message if the attribute already exists it will be replaced if the threadsSafe flag is set to true, the method will lock the map if attrs map is empty in the struct, it will be created
func (*MapAttributes) ThreadSafe ¶
func (m *MapAttributes) ThreadSafe(ts bool)
ThreadSafe makes the attributes thread safe
type Properties ¶
Properties struct to hold the properties values
func (*Properties) Get ¶
func (p *Properties) Get(k, d string) string
Get Function will return the string for the specified key. If no value is present for the corresponding key then the default value is returned.
func (*Properties) GetAsBool ¶
func (p *Properties) GetAsBool(k string, defaultVal bool) (bool, error)
GetAsBool Function will return the value as int64 for the specified key.If no value is present for the corresponding key then the default value is returned.In case the value is present and it is not a bool is thrown.
func (*Properties) GetAsDecimal ¶
func (p *Properties) GetAsDecimal(k string, defaultVal float64) (float64, error)
GetAsDecimal Function will return the value as int64 for the specified key.If no value is present for the corresponding key then the default value is returned.In case the value is present and it is not decimal error is thrown.
func (*Properties) GetAsInt ¶
func (p *Properties) GetAsInt(k string, defaultVal int) (int, error)
GetAsInt Function will return the value as int for the specified key. If no value is present for the corresponding key then the default value is returned.In case the value is present and it is not a int an error is thrown.
func (*Properties) GetAsInt64 ¶
func (p *Properties) GetAsInt64(k string, defaultVal int64) (int64, error)
GetAsInt64 Function will return the value as int64 for the specified key. If no value is present for the corresponding key then the default value is returned.In case the value is present and it is not a int64 an error is thrown.
func (*Properties) Load ¶
func (p *Properties) Load(r io.Reader) error
Load function will read the properties from a io.Reader. This function does not close the reader and it is the responsibility of the caller to close the reader
func (*Properties) Put ¶
func (p *Properties) Put(k, v string) string
Put function will add the key,value to the properties. If the property was already present then the previous values is returned
func (*Properties) PutBool ¶
func (p *Properties) PutBool(k string, v bool) (bool, error)
PutBool function will add the key,value to the properties. The value is accepted as bool however is is stored as a string. If the property was already present then the previous values is returned
func (*Properties) PutDecimal ¶
func (p *Properties) PutDecimal(k string, v float64) (float64, error)
PutDecimal function will add the key,value to the properties. The value is accepted as decimal however is is stored as a string. If the property was already present then the previous values is returned
func (*Properties) PutInt ¶
func (p *Properties) PutInt(k string, v int) (int, error)
PutInt function will add the key,value to the properties. The value is accepted as int however is stored as a string If the property was already present then the previous values is returned
func (*Properties) PutInt64 ¶
func (p *Properties) PutInt64(k string, v int64) (int64, error)
PutInt64 function will add the key,value to the properties. The value is accepted as int64 however is is stored as a string. If the property was already present then the previous values is returned
func (*Properties) Save ¶
func (p *Properties) Save(w io.Writer) error
Save function will read the properties from a io.Writer. If error occurs while writing to the reader, this will immediately return the error.This may cause partial writes. This function does not close the writer and it is the responsibility of the caller to close the writer