defaults dont work for conf
This commit is contained in:
@@ -2,6 +2,8 @@ package config
|
||||
|
||||
import (
|
||||
"local/rproxy3/storage/packable"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -52,3 +54,25 @@ func notEmpty(s ...string) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func GetRate() (int, int) {
|
||||
r := packable.NewString()
|
||||
conf.Get(nsConf, flagRate, r)
|
||||
b := packable.NewString()
|
||||
conf.Get(nsConf, flagBurst, b)
|
||||
|
||||
rate, _ := strconv.Atoi(r.String())
|
||||
burst, _ := strconv.Atoi(b.String())
|
||||
|
||||
return rate, burst
|
||||
}
|
||||
|
||||
func GetTimeout() int {
|
||||
t := packable.NewString()
|
||||
conf.Get(nsConf, flagTimeout, t)
|
||||
|
||||
timeout, _ := strconv.Atoi(t.String())
|
||||
log.Printf("TIMEOUT t:%q, i:%v", t.String(), timeout)
|
||||
|
||||
return timeout
|
||||
}
|
||||
|
||||
@@ -20,6 +20,9 @@ const flagCert = "crt"
|
||||
const flagKey = "key"
|
||||
const flagUser = "user"
|
||||
const flagPass = "pass"
|
||||
const flagRate = "rate"
|
||||
const flagBurst = "burst"
|
||||
const flagTimeout = "timeout"
|
||||
|
||||
var conf = storage.NewMap()
|
||||
|
||||
@@ -35,6 +38,9 @@ type fileConf struct {
|
||||
KeyPath string `yaml:"key"`
|
||||
Username string `yaml:"user"`
|
||||
Password string `yaml:"pass"`
|
||||
Rate string `yaml:"rate"`
|
||||
Burst string `yaml:"burst"`
|
||||
Timeout string `yaml:"timeout"`
|
||||
}
|
||||
|
||||
func Init() error {
|
||||
@@ -85,6 +91,15 @@ func fromFile() error {
|
||||
if err := conf.Set(nsConf, flagPass, packable.NewString(c.Password)); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := conf.Set(nsConf, flagRate, packable.NewString(c.Rate)); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := conf.Set(nsConf, flagBurst, packable.NewString(c.Burst)); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := conf.Set(nsConf, flagTimeout, packable.NewString(c.Timeout)); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -97,10 +112,14 @@ func fromFlags() error {
|
||||
binds = append(binds, addFlag(flagKey, "", "path to .key"))
|
||||
binds = append(binds, addFlag(flagUser, "", "basic auth username"))
|
||||
binds = append(binds, addFlag(flagPass, "", "basic auth password"))
|
||||
binds = append(binds, addFlag(flagRate, "100", "rate limit per second"))
|
||||
binds = append(binds, addFlag(flagBurst, "100", "rate limit burst"))
|
||||
binds = append(binds, addFlag(flagTimeout, "30", "seconds to wait for limiter"))
|
||||
flag.Parse()
|
||||
|
||||
for _, bind := range binds {
|
||||
confFlag := flag.Lookup(bind.flag)
|
||||
log.Printf("flag:%v", confFlag)
|
||||
if confFlag == nil || confFlag.Value.String() == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user