@@ 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 {