Esempio n. 1
0
func initConsul(cfg *config.Config) {
	consul.Addr = cfg.Consul.Addr
	consul.URL = cfg.Consul.URL

	dc, err := consul.Datacenter()
	if err != nil {
		log.Fatal("[FATAL] ", err)
	}

	log.Printf("[INFO] Connecting to consul on %q in datacenter %q", cfg.Consul.Addr, dc)
	log.Printf("[INFO] Consul can be reached via %q", cfg.Consul.URL)
}
Esempio n. 2
0
func handleRoute(w http.ResponseWriter, r *http.Request) {
	dc, err := consul.Datacenter()
	if err != nil {
		http.Error(w, "cannot get datacenter: "+err.Error(), http.StatusInternalServerError)
		return
	}

	data := struct {
		Config    []string
		ConfigURL string
	}{
		route.GetTable().Config(true),
		fmt.Sprintf("%sui/#/%s/kv%s/edit", consul.URL, dc, configPath),
	}
	tmplTable.ExecuteTemplate(w, "table", data)
}
Esempio n. 3
0
func main() {
	var cfg string
	var v bool
	flag.StringVar(&cfg, "cfg", "", "path to config file")
	flag.BoolVar(&v, "v", false, "show version")
	flag.Parse()

	if v {
		fmt.Println(version)
		return
	}

	log.Printf("[INFO] Version %s starting", version)

	if cfg != "" {
		if err := loadConfig(cfg); err != nil {
			log.Fatal("[FATAL] ", err)
		}
	}

	if err := metrics.Init(metricsTarget, metricsPrefix, metricsInterval, metricsGraphiteAddr); err != nil {
		log.Fatal("[FATAL] ", err)
	}

	if os.Getenv("GOMAXPROCS") == "" {
		log.Print("[INFO] Setting GOMAXPROCS=", gomaxprocs)
		runtime.GOMAXPROCS(gomaxprocs)
	} else {
		log.Print("[INFO] Using GOMAXPROCS=", os.Getenv("GOMAXPROCS"), " from env")
	}

	if os.Getenv("GOGC") == "" {
		log.Print("[INFO] Setting GOGC=", gogc)
		debug.SetGCPercent(gogc)
	} else {
		log.Print("[INFO] Using GOGC=", os.Getenv("GOGC"), " from env")
	}

	if proxyRoutes == "" {
		useDynamicRoutes()
	} else {
		useStaticRoutes()
	}

	if err := route.SetPickerStrategy(proxyStrategy); err != nil {
		log.Fatal("[FATAL] ", err)
	}

	consul.Addr = consulAddr
	consul.URL = consulURL

	dc, err := consul.Datacenter()
	if err != nil {
		log.Fatal("[FATAL] ", err)
	}

	log.Printf("[INFO] Using routing strategy %q", proxyStrategy)
	log.Printf("[INFO] Connecting to consul on %q in datacenter %q", consulAddr, dc)
	log.Printf("[INFO] Consul can be reached via %q", consulURL)

	log.Printf("[INFO] UI listening on %q", uiAddr)
	go func() {
		if err := ui.Start(uiAddr, consulKVPath); err != nil {
			log.Fatal("[FATAL] ui: ", err)
		}
	}()

	tr := &http.Transport{
		ResponseHeaderTimeout: proxyTimeout,
		MaxIdleConnsPerHost:   proxyMaxConn,
		Dial: (&net.Dialer{
			Timeout:   proxyDialTimeout,
			KeepAlive: proxyTimeout,
		}).Dial,
	}

	proxy := route.NewProxy(tr, proxyHeaderClientIP, proxyHeaderTLS, proxyHeaderTLSValue)
	listen(proxyAddr, proxyShutdownWait, proxy)
}