|
|
|
@ -14,14 +14,14 @@ import ( |
|
|
|
|
var ( |
|
|
|
|
// Get the desired configuration value.
|
|
|
|
|
Get struct { |
|
|
|
|
Debug bool `yaml:"debug"` |
|
|
|
|
Folder string `yaml:"folder"` |
|
|
|
|
Host string `yaml:"host"` |
|
|
|
|
Port uint16 `yaml:"port"` |
|
|
|
|
ShowListing bool `yaml:"show-listing"` |
|
|
|
|
TLSCert string `yaml:"tls-cert"` |
|
|
|
|
TLSKey string `yaml:"tls-key"` |
|
|
|
|
URLPrefix string `yaml:"url-prefix"` |
|
|
|
|
Debug bool `yaml:"debug"` |
|
|
|
|
Folder string `yaml:"folder"` |
|
|
|
|
Host string `yaml:"host"` |
|
|
|
|
Port uint16 `yaml:"port"` |
|
|
|
|
ShowListing bool `yaml:"show-listing"` |
|
|
|
|
TLSCert string `yaml:"tls-cert"` |
|
|
|
|
TLSKey string `yaml:"tls-key"` |
|
|
|
|
URLPrefix string `yaml:"url-prefix"` |
|
|
|
|
Referrers []string `yaml:"referrers"` |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
@ -31,18 +31,19 @@ const ( |
|
|
|
|
folderKey = "FOLDER" |
|
|
|
|
hostKey = "HOST" |
|
|
|
|
portKey = "PORT" |
|
|
|
|
referrersKey = "REFERRERS" |
|
|
|
|
showListingKey = "SHOW_LISTING" |
|
|
|
|
tlsCertKey = "TLS_CERT" |
|
|
|
|
tlsKeyKey = "TLS_KEY" |
|
|
|
|
urlPrefixKey = "URL_PREFIX" |
|
|
|
|
referrersKey = "REFERRERS" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
|
var ( |
|
|
|
|
defaultDebug = false |
|
|
|
|
defaultFolder = "/web" |
|
|
|
|
defaultHost = "" |
|
|
|
|
defaultPort = uint16(8080) |
|
|
|
|
defaultReferrers = []string{} |
|
|
|
|
defaultShowListing = true |
|
|
|
|
defaultTLSCert = "" |
|
|
|
|
defaultTLSKey = "" |
|
|
|
@ -59,11 +60,11 @@ func setDefaults() { |
|
|
|
|
Get.Folder = defaultFolder |
|
|
|
|
Get.Host = defaultHost |
|
|
|
|
Get.Port = defaultPort |
|
|
|
|
Get.Referrers = defaultReferrers |
|
|
|
|
Get.ShowListing = defaultShowListing |
|
|
|
|
Get.TLSCert = defaultTLSCert |
|
|
|
|
Get.TLSKey = defaultTLSKey |
|
|
|
|
Get.URLPrefix = defaultURLPrefix |
|
|
|
|
Get.Referrers = nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Load the configuration file.
|
|
|
|
@ -111,7 +112,7 @@ func overrideWithEnvVars() { |
|
|
|
|
Get.TLSCert = envAsStr(tlsCertKey, Get.TLSCert) |
|
|
|
|
Get.TLSKey = envAsStr(tlsKeyKey, Get.TLSKey) |
|
|
|
|
Get.URLPrefix = envAsStr(urlPrefixKey, Get.URLPrefix) |
|
|
|
|
Get.Referrers = strAsArray(envAsStr(referrersKey, "")) |
|
|
|
|
Get.Referrers = envAsStrSlice(referrersKey, Get.Referrers) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// validate the configuration.
|
|
|
|
@ -154,6 +155,15 @@ func envAsStr(key, fallback string) string { |
|
|
|
|
return fallback |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// envAsStrSlice returns the value of the environment variable as a slice of
|
|
|
|
|
// strings if set.
|
|
|
|
|
func envAsStrSlice(key string, fallback []string) []string { |
|
|
|
|
if value := os.Getenv(key); "" != value { |
|
|
|
|
return strings.Split(value, ",") |
|
|
|
|
} |
|
|
|
|
return fallback |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// envAsUint16 returns the value of the environment variable as a uint16 if set.
|
|
|
|
|
func envAsUint16(key string, fallback uint16) uint16 { |
|
|
|
|
// Retrieve the string value of the environment variable. If not set,
|
|
|
|
@ -215,11 +225,3 @@ func strAsBool(value string) (result bool, err error) { |
|
|
|
|
} |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func strAsArray(value string) (result []string) { |
|
|
|
|
if (value == "") { |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
result = strings.Split(value, ","); |
|
|
|
|
return |
|
|
|
|
} |