46 lines
1.1 KiB
Go
Executable File
46 lines
1.1 KiB
Go
Executable File
package config
|
|
|
|
import (
|
|
"flag"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
func flagEnvFallback(keyFallback map[string]string) map[string]string {
|
|
results := map[string]*string{}
|
|
for k, v := range keyFallback {
|
|
results[k] = flag.String(k, v, "")
|
|
}
|
|
flag.Parse()
|
|
final := map[string]string{}
|
|
for k := range results {
|
|
if *results[k] == keyFallback[k] && os.Getenv(strings.ToUpper(k)) != "" {
|
|
*results[k] = os.Getenv(strings.ToUpper(k))
|
|
}
|
|
final[k] = *results[k]
|
|
}
|
|
return final
|
|
}
|
|
|
|
func New() map[string]string {
|
|
conf := flagEnvFallback(map[string]string{
|
|
"toaddr": "https://bel.house:20018",
|
|
"mycrt": "/Volumes/bldisk/client.crt",
|
|
"mykey": "/Volumes/bldisk/client.key",
|
|
"tocrt": "/Volumes/bldisk/server.crt",
|
|
"fromcrt": "/Volumes/bldisk/accept.crt",
|
|
"port": "8888",
|
|
"whitelist": "192.168.0.86,,bel.house,,minio.gcp.blapointe.com",
|
|
"bypass": "plex.tv",
|
|
"secure": "gcp.blapointe.com",
|
|
"secret": "secret",
|
|
})
|
|
if !strings.HasPrefix(conf["port"], ":") {
|
|
conf["port"] = ":" + conf["port"]
|
|
}
|
|
if len(conf["bypass"]) != 0 {
|
|
conf["whitelist"] += ",," + conf["bypass"]
|
|
}
|
|
return conf
|
|
}
|