@@ 27,7 27,7 @@ var (
internalIPNet []net.IPNet
)
-// Loads the application configuration.
+// LoadConfig loads the application configuration.
func LoadConfig() ini.File {
var (
config ini.File
@@ 85,8 85,22 @@ func LoadConfig() ini.File {
return config
}
-// Returns the URL (scheme, host, port) at which the web application for a
-// given service can be found.
+// GetOwner returns the owner name and email. Panics if not configured.
+func GetOwner(conf ini.File) (ownerName, ownerEmail string) {
+ var ok bool
+ ownerName, ok = conf.Get("sr.ht", "owner-name")
+ if !ok {
+ panic("missing [sr.ht]owner-name in config")
+ }
+ ownerEmail, ok = conf.Get("sr.ht", "owner-email")
+ if !ok {
+ panic("missing [sr.ht]owner-email in config")
+ }
+ return
+}
+
+// GetOrigin returns the URL (scheme, host, port) at which the web application
+// for a given service can be found.
//
// Set "external" to true if the URL will be accessed by an external user (i.e.
// outside of the LAN).
@@ 103,8 117,8 @@ func GetOrigin(conf ini.File, svc string, external bool) string {
return origin
}
-// Returns the URL (scheme, host, port) at which the API for a given service
-// can be found. Does not include the /query path!
+// GetAPI returns the URL (scheme, host, port) at which the API for a given
+// service can be found. Does not include the /query path!
//
// Set "external" to true if the URL will be accessed by an external user (i.e.
// outside of the LAN).
@@ 137,8 151,18 @@ func GetAPI(conf ini.File, svc string, external bool) string {
const DefaultQueueSize = 512
-// Returns the configured integer value for the given section and variable name.
-// If nothing is configured, the default value will be returned.
+// GetString returns the configured string value for the given section and
+// variable name. If nothing is configured, the default value will be returned.
+func GetString(conf ini.File, section, name string, defValue string) string {
+ value, ok := conf.Get(section, name)
+ if !ok {
+ value = defValue
+ }
+ return value
+}
+
+// GetInt returns the configured integer value for the given section and
+// variable name. If nothing is configured, the default value will be returned.
// If an invalid integer is configured, this function will panic.
func GetInt(conf ini.File, section, name string, defValue int) int {
value := defValue
@@ 151,8 175,8 @@ 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.
+// GetBool 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
@@ 169,8 193,8 @@ func GetBool(conf ini.File, section, name string, defValue bool) bool {
return value
}
-// Returns true if the given IP address is part of the internal networks as
-// per the configuration of [sr.ht]internal-ipnet.
+// IsInternalIP 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 {
for _, net := range internalIPNet {
if net.Contains(ip) {