package config import ( "fmt" "log" "strings" "time" ) type Proxy struct { To string } func parseProxy(s string) (string, Proxy) { p := Proxy{} key := "" l := strings.Split(s, ",") if len(l) > 0 { key = l[0] } if len(l) > 1 { p.To = l[1] } return key, p } func GetBOAuthZ() (string, bool) { boauthz := conf.Get("oauth").GetString() return boauthz, boauthz != "" } func GetAuth() (string, string, bool) { user := conf.Get("user").GetString() pass := conf.Get("pass").GetString() return user, pass, user != "" && pass != "" } func GetPort() string { port := conf.Get("p").GetInt() return ":" + fmt.Sprint(port) } func GetRate() (int, int) { rate := conf.Get("r").GetInt() burst := conf.Get("b").GetInt() log.Println("rate/burst:", rate, burst) return rate, burst } func GetRoutes() map[string]Proxy { list := conf.Get("proxy").GetString() definitions := strings.Split(list, ",,") routes := make(map[string]Proxy) for _, definition := range definitions { k, v := parseProxy(definition) routes[k] = v } return routes } func GetSSL() (string, string, bool) { crt := conf.Get("crt").GetString() key := conf.Get("key").GetString() return crt, key, crt != "" && key != "" } func GetTCP() (string, bool) { tcp := conf.Get("tcp").GetString() return tcp, tcp != "" } func GetTimeout() time.Duration { timeout := conf.Get("timeout").GetDuration() return timeout }