Documentation
¶
Overview ¶
Package knf provides methods for working with configs in KNF format
Index ¶
- func GetB(name string, defvals ...bool) bool
- 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) GetB(name string, defvals ...bool) bool
- 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 ¶
This section is empty.
Functions ¶
func Global ¶
Global reads and parses config file Global config will be accessible globally 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")
// 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")
func Reload ¶
Reload reads and parse global config 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)
}
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config is basic config struct
func (*Config) HasSection ¶
HasSection check 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.