Documentation ¶
Overview ¶
Package knf provides methods for working with configuration files in KNF format
Index ¶
- Variables
- func GetB(name string, defvals ...bool) bool
- func GetD(name string, defvals ...time.Duration) time.Duration
- func GetF(name string, defvals ...float64) float64
- func GetI(name string, defvals ...int) int
- func GetI64(name string, defvals ...int64) int64
- func GetM(name string, defvals ...os.FileMode) os.FileMode
- func GetS(name string, defvals ...string) string
- func GetU(name string, defvals ...uint) uint
- func GetU64(name string, defvals ...uint64) uint64
- func Global(file string) error
- func HasProp(name string) bool
- func HasSection(section string) bool
- func Props(section string) []string
- func Reload() (map[string]bool, error)
- func Sections() []string
- func Validate(validators []*Validator) []error
- type Config
- func (c *Config) File() string
- func (c *Config) GetB(name string, defvals ...bool) bool
- func (c *Config) GetD(name string, defvals ...time.Duration) time.Duration
- func (c *Config) GetF(name string, defvals ...float64) float64
- func (c *Config) GetI(name string, defvals ...int) int
- func (c *Config) GetI64(name string, defvals ...int64) int64
- func (c *Config) GetM(name string, defvals ...os.FileMode) os.FileMode
- func (c *Config) GetS(name string, defvals ...string) string
- func (c *Config) GetU(name string, defvals ...uint) uint
- func (c *Config) GetU64(name string, defvals ...uint64) uint64
- func (c *Config) HasProp(name string) bool
- func (c *Config) HasSection(section string) bool
- func (c *Config) Props(section string) []string
- func (c *Config) Reload() (map[string]bool, error)
- func (c *Config) Sections() []string
- func (c *Config) Validate(validators []*Validator) []error
- type PropertyValidator
- type Validator
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrConfigIsNil = errors.New("Config struct is nil") ErrFileNotSet = errors.New("Path to config file is empty (non initialized struct?)") )
Functions ¶
func Global ¶
Global reads and parses configuration file Global instance is accessible from any part of the code
Example ¶
// Load global config err := Global("/path/to/your/config.knf") if err != nil { fmt.Printf("Error: %v\n", err) return } // Read string value GetS("section:string") // Read integer value GetI("section:int") // Read float value GetF("section:float") // Read boolean value GetB("section:boolean") // Read file mode value GetM("section:file-mode") // Read duration in seconds GetD("section:duration") // Check section if HasSection("section") { // Section exist } // Check property if HasProp("section:string") { // Property exist } // Slice of all sections Sections() // Slice of all properties in section Props("section")
Output:
func Reload ¶
Reload reloads global configuration file
Example ¶
err := Global("/path/to/your/config.knf") if err != nil { fmt.Printf("Error: %v\n", err) return } changes, err := Reload() if err != nil { fmt.Printf("Error: %v\n", err) return } // Print info about changed values for prop, changed := range changes { fmt.Printf("Property %s changed → %t\n", prop, changed) }
Output:
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config is basic config struct
func (*Config) HasSection ¶
HasSection checks if section exist
type PropertyValidator ¶
PropertyValidator is default type of property validation function
type Validator ¶
type Validator struct { Property string // Property name Func PropertyValidator // Validation function Value interface{} // Expected value }
Validator is config property validator struct
Directories ¶
Path | Synopsis |
---|---|
Package validators provides basic KNF validators
|
Package validators provides basic KNF validators |
fs
Package fs provides KNF validators for checking file-system items
|
Package fs provides KNF validators for checking file-system items |
network
Package network provides KNF validators for checking items related to network
|
Package network provides KNF validators for checking items related to network |
regexp
Package regexp provides KNF validators with regular expressions
|
Package regexp provides KNF validators with regular expressions |
system
Package system provides KNF validators for checking system items (user, groups, network interfaces) Package system provides KNF validators for checking system items (user, groups, network interfaces)
|
Package system provides KNF validators for checking system items (user, groups, network interfaces) Package system provides KNF validators for checking system items (user, groups, network interfaces) |
Click to show internal directories.
Click to hide internal directories.