- Better settings tree structure logged using `qdm12/gotree` - Read settings from environment variables, then files, then secret files - Settings methods to default them, merge them and override them - `DNS_PLAINTEXT_ADDRESS` default changed to `127.0.0.1` to use DoT. Warning added if set to something else. - `HTTPPROXY_LISTENING_ADDRESS` instead of `HTTPPROXY_PORT` (with retro-compatibility)
46 lines
860 B
Go
46 lines
860 B
Go
package helpers
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
func IsOneOf(value string, choices ...string) (ok bool) {
|
|
for _, choice := range choices {
|
|
if value == choice {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
var ErrValueNotOneOf = errors.New("value is not one of the possible choices")
|
|
|
|
func AreAllOneOf(values, choices []string) (err error) {
|
|
set := make(map[string]struct{}, len(choices))
|
|
for _, choice := range choices {
|
|
choice = strings.ToLower(choice)
|
|
set[choice] = struct{}{}
|
|
}
|
|
|
|
for _, value := range values {
|
|
_, ok := set[value]
|
|
if !ok {
|
|
return fmt.Errorf("%w: value %q, choices available are %s",
|
|
ErrValueNotOneOf, value, strings.Join(choices, ", "))
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func Uint16IsOneOf(port uint16, choices []uint16) (ok bool) {
|
|
for _, choice := range choices {
|
|
if port == choice {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|