Beispiel #1
0
func FromProperties(p *properties.Properties) (*Config, error) {
	var cfg *Config = &Config{}
	var err error

	cfg.Proxy = Proxy{
		MaxConn:               p.GetInt("proxy.maxconn", DefaultConfig.Proxy.MaxConn),
		Strategy:              p.GetString("proxy.strategy", DefaultConfig.Proxy.Strategy),
		ShutdownWait:          p.GetParsedDuration("proxy.shutdownwait", DefaultConfig.Proxy.ShutdownWait),
		DialTimeout:           p.GetParsedDuration("proxy.dialtimeout", DefaultConfig.Proxy.DialTimeout),
		ResponseHeaderTimeout: p.GetParsedDuration("proxy.timeout", DefaultConfig.Proxy.ResponseHeaderTimeout),
		KeepAliveTimeout:      p.GetParsedDuration("proxy.timeout", DefaultConfig.Proxy.KeepAliveTimeout),
		LocalIP:               p.GetString("proxy.localip", DefaultConfig.Proxy.LocalIP),
		ClientIPHeader:        p.GetString("proxy.header.clientip", DefaultConfig.Proxy.ClientIPHeader),
		TLSHeader:             p.GetString("proxy.header.tls", DefaultConfig.Proxy.TLSHeader),
		TLSHeaderValue:        p.GetString("proxy.header.tls.value", DefaultConfig.Proxy.TLSHeaderValue),
	}

	cfg.Listen, err = parseListen(p.GetString("proxy.addr", DefaultConfig.Listen[0].Addr))
	if err != nil {
		return nil, err
	}

	cfg.Routes = p.GetString("proxy.routes", "")

	cfg.Metrics = parseMetrics(
		p.GetString("metrics.target", ""),
		p.GetString("metrics.prefix", "default"),
		p.GetString("metrics.graphite.addr", ""),
		p.GetParsedDuration("metrics.interval", 30*time.Second),
	)

	cfg.Consul = Consul{
		Addr:      p.GetString("consul.addr", DefaultConfig.Consul.Addr),
		KVPath:    p.GetString("consul.kvpath", DefaultConfig.Consul.KVPath),
		TagPrefix: p.GetString("consul.tagprefix", DefaultConfig.Consul.TagPrefix),
		URL:       p.GetString("consul.url", DefaultConfig.Consul.URL),
	}

	cfg.Runtime = Runtime{
		GOGC:       p.GetInt("runtime.gogc", DefaultConfig.Runtime.GOGC),
		GOMAXPROCS: p.GetInt("runtime.gomaxprocs", DefaultConfig.Runtime.GOMAXPROCS),
	}
	if cfg.Runtime.GOMAXPROCS == -1 {
		cfg.Runtime.GOMAXPROCS = runtime.NumCPU()
	}

	cfg.UI = UI{
		Addr: p.GetString("ui.addr", DefaultConfig.UI.Addr),
	}

	return cfg, nil
}
Beispiel #2
0
func FromProperties(p *properties.Properties) (cfg *Config, err error) {
	cfg = &Config{}

	deprecate := func(key, msg string) {
		_, exists := p.Get(key)
		if exists {
			log.Print("[WARN] config: ", msg)
		}
	}

	cfg.Proxy = Proxy{
		MaxConn:               p.GetInt("proxy.maxconn", DefaultConfig.Proxy.MaxConn),
		Strategy:              p.GetString("proxy.strategy", DefaultConfig.Proxy.Strategy),
		ShutdownWait:          p.GetParsedDuration("proxy.shutdownwait", DefaultConfig.Proxy.ShutdownWait),
		DialTimeout:           p.GetParsedDuration("proxy.dialtimeout", DefaultConfig.Proxy.DialTimeout),
		ResponseHeaderTimeout: p.GetParsedDuration("proxy.timeout", DefaultConfig.Proxy.ResponseHeaderTimeout),
		KeepAliveTimeout:      p.GetParsedDuration("proxy.timeout", DefaultConfig.Proxy.KeepAliveTimeout),
		LocalIP:               p.GetString("proxy.localip", DefaultConfig.Proxy.LocalIP),
		ClientIPHeader:        p.GetString("proxy.header.clientip", DefaultConfig.Proxy.ClientIPHeader),
		TLSHeader:             p.GetString("proxy.header.tls", DefaultConfig.Proxy.TLSHeader),
		TLSHeaderValue:        p.GetString("proxy.header.tls.value", DefaultConfig.Proxy.TLSHeaderValue),
	}

	cfg.Listen, err = parseListen(p.GetString("proxy.addr", DefaultConfig.Listen[0].Addr))
	if err != nil {
		return nil, err
	}

	cfg.Routes = p.GetString("proxy.routes", "")

	cfg.Metrics = parseMetrics(
		p.GetString("metrics.target", ""),
		p.GetString("metrics.prefix", "default"),
		p.GetString("metrics.graphite.addr", ""),
		p.GetParsedDuration("metrics.interval", 30*time.Second),
	)

	cfg.Consul = Consul{
		Addr:          p.GetString("consul.addr", DefaultConfig.Consul.Addr),
		Token:         p.GetString("consul.token", DefaultConfig.Consul.Token),
		KVPath:        p.GetString("consul.kvpath", DefaultConfig.Consul.KVPath),
		TagPrefix:     p.GetString("consul.tagprefix", DefaultConfig.Consul.TagPrefix),
		ServiceName:   p.GetString("consul.register.name", DefaultConfig.Consul.ServiceName),
		CheckInterval: p.GetParsedDuration("consul.register.checkInterval", DefaultConfig.Consul.CheckInterval),
		CheckTimeout:  p.GetParsedDuration("consul.register.checkTimeout", DefaultConfig.Consul.CheckTimeout),
	}
	deprecate("consul.url", "consul.url is obsolete. Please remove it.")

	cfg.Runtime = Runtime{
		GOGC:       p.GetInt("runtime.gogc", DefaultConfig.Runtime.GOGC),
		GOMAXPROCS: p.GetInt("runtime.gomaxprocs", DefaultConfig.Runtime.GOMAXPROCS),
	}
	if cfg.Runtime.GOMAXPROCS == -1 {
		cfg.Runtime.GOMAXPROCS = runtime.NumCPU()
	}

	cfg.UI = UI{
		Addr:  p.GetString("ui.addr", DefaultConfig.UI.Addr),
		Color: p.GetString("ui.color", DefaultConfig.UI.Color),
		Title: p.GetString("ui.title", DefaultConfig.UI.Title),
	}

	return cfg, nil
}