예제 #1
0
파일: init.go 프로젝트: juliendsv/fabio
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)
}
예제 #2
0
파일: route.go 프로젝트: noxiouz/fabio
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)
}
예제 #3
0
파일: main.go 프로젝트: jeinwag/fabio
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)
}