uses conf file now
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"local/rproxy3/storage"
|
||||
"local/rproxy3/storage/packable"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
@@ -28,9 +29,9 @@ type toBind struct {
|
||||
}
|
||||
|
||||
type fileConf struct {
|
||||
Port string `yaml:"port"`
|
||||
Routes []string `yaml:"routes"`
|
||||
CertPath string `yaml:"cert"`
|
||||
Port string `yaml:"p"`
|
||||
Routes []string `yaml:"r"`
|
||||
CertPath string `yaml:"crt"`
|
||||
KeyPath string `yaml:"key"`
|
||||
Username string `yaml:"user"`
|
||||
Password string `yaml:"pass"`
|
||||
@@ -48,7 +49,12 @@ func Init() error {
|
||||
}
|
||||
|
||||
func fromFile() error {
|
||||
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
|
||||
defer func() {
|
||||
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
|
||||
}()
|
||||
flag.String(flagConf, "/dev/null", "yaml config file path")
|
||||
flag.Parse()
|
||||
confFlag := flag.Lookup(flagConf)
|
||||
if confFlag == nil || confFlag.Value.String() == "" {
|
||||
return nil
|
||||
@@ -85,6 +91,7 @@ func fromFile() error {
|
||||
func fromFlags() error {
|
||||
binds := make([]toBind, 0)
|
||||
binds = append(binds, addFlag(flagPort, "51555", "port to bind to"))
|
||||
binds = append(binds, addFlag(flagConf, "", "configuration file path"))
|
||||
binds = append(binds, addFlag(flagRoutes, "", "comma-separated routes to map, each as from:scheme://to.tld:port"))
|
||||
binds = append(binds, addFlag(flagCert, "", "path to .crt"))
|
||||
binds = append(binds, addFlag(flagKey, "", "path to .key"))
|
||||
@@ -106,9 +113,18 @@ func fromFlags() error {
|
||||
}
|
||||
|
||||
func addFlag(key, def, help string) toBind {
|
||||
def = getFlagOrDefault(key, def)
|
||||
v := flag.String(key, def, help)
|
||||
return toBind{
|
||||
flag: key,
|
||||
value: v,
|
||||
}
|
||||
}
|
||||
|
||||
func getFlagOrDefault(key, def string) string {
|
||||
v := packable.NewString()
|
||||
if err := conf.Get(nsConf, key, v); err != nil {
|
||||
return def
|
||||
}
|
||||
return v.String()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user