Skip to content

Commit

Permalink
Merge pull request #447 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 12.109.0
  • Loading branch information
andyone authored Mar 21, 2024
2 parents 5a02e8f + d748b40 commit 22ab8cb
Show file tree
Hide file tree
Showing 7 changed files with 626 additions and 573 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## Changelog

### 12.109.0

* `[support]` Added custom checks support
* `[knf/united]` Improved handling of environment variables
* `[support]` Improved application info formatting
* `[support]` Code refactoring
* `[support]` Added more tests

### 12.108.1

* `[support]` Fixed documentation formatting
Expand Down
2 changes: 1 addition & 1 deletion ek.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
// ////////////////////////////////////////////////////////////////////////////////// //

// VERSION is current ek package version
const VERSION = "12.108.1"
const VERSION = "12.109.0"

// ////////////////////////////////////////////////////////////////////////////////// //

Expand Down
16 changes: 14 additions & 2 deletions knf/united/united.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
// Config is extended configuration
type config struct {
mappings map[string]Mapping
env map[string]string
}

// Mapping contains mapping [knf property] → [option] → [envvar]
Expand Down Expand Up @@ -60,13 +61,22 @@ var optionGetFunc = options.GetS

// Combine applies mappings to combine knf properties, options, and environment
// variables
//
// Note that the environment variable will be moved to config after combining (e.g.
// won't be accessible with os.Getenv)
func Combine(mappings ...Mapping) {
config := &config{
mappings: make(map[string]Mapping),
env: make(map[string]string),
}

for _, m := range mappings {
config.mappings[m.Property] = m

if m.Variable != "" {
config.env[m.Variable] = os.Getenv(m.Variable)
os.Setenv(m.Variable, "")
}
}

global = config
Expand Down Expand Up @@ -309,6 +319,7 @@ func (c *config) GetL(name string, defvals ...[]string) []string {

// ////////////////////////////////////////////////////////////////////////////////// //

// getProp returns property value for knf configuration, env vars, or options
func (c *config) getProp(name string) string {
m := c.mappings[name]

Expand All @@ -319,13 +330,14 @@ func (c *config) getProp(name string) string {
switch {
case m.Option != "" && optionHasFunc(m.Option):
return optionGetFunc(m.Option)
case m.Variable != "" && os.Getenv(m.Variable) != "":
return os.Getenv(m.Variable)
case m.Variable != "" && c.env[m.Variable] != "":
return c.env[m.Variable]
default:
return knf.GetS(name)
}
}

// validate runs validators over configuration
func validate(validators []*knf.Validator) []error {
var result []error

Expand Down
Loading

0 comments on commit 22ab8cb

Please sign in to comment.