~bigbes/core-go

c1d572b5420100f950dfaa0e6e3a6b86526dd398 — Conrad Hoffmann 1 year, 3 months ago 55ab6c4
config: add GetBool convenience method

It's the boolean equivalent of `GetInt()`. The value handling is taken
from the Python version (`srht.config.cfgb()`).
1 files changed, 18 insertions(+), 0 deletions(-)

M config/config.go
M config/config.go => config/config.go +18 -0
@@ 129,6 129,24 @@ func GetInt(conf ini.File, section, name string, defValue int) int {
	return value
}

// Returns the configured boolean value for the given section and variable name.
// If nothing is configured, the default value will be returned.
// If an invalid boolean is configured, this function will panic.
func GetBool(conf ini.File, section, name string, defValue bool) bool {
	value := defValue
	if s, ok := conf.Get(section, name); ok {
		switch s {
		case "true", "yes", "on", "1":
			value = true
		case "false", "no", "off", "0":
			value = false
		default:
			panic(fmt.Errorf("[%s]%s: invalid boolean value", section, name))
		}
	}
	return value
}

// Returns true if the given IP address is part of the internal networks as
// per the configuration of [sr.ht]internal-ipnet.
func IsInternalIP(ip net.IP) bool {