예제 #1
0
파일: run.go 프로젝트: pdxjohnny/discovery
func Run() {
	proxy := NewBaseManager()
	// If we only want to proxy to a single url
	if viper.GetString("url") != "" {
		proxy.Add(viper.GetString("url"))
	}

	// If we want to accept new frontends
	if viper.GetBool("discover") {
		discover := NewDiscoveryService(proxy)
		crypto.LoadKey(
			discover,
			viper.GetString("dKey"),
			"private",
		)
		discover.password = crypto.Sha(viper.GetString("dPass"), 10)
		go proxy.Discover(
			discover,
			viper.GetString("dAddr"),
			viper.GetString("dPort"),
		)
	}

	// Server the reverse proxy server
	mux := http.NewServeMux()
	mux.HandleFunc("/", Handler(proxy))
	err := http.ListenAndServe(":"+viper.GetString("port"), mux)
	if err != nil {
		log.Println("ERROR serving ReverseProxy:\t", err)
	}
}
예제 #2
0
파일: run.go 프로젝트: pdxjohnny/discovery
func Run() {
	mux := http.NewServeMux()
	mux.HandleFunc("/", sayhelloName)

	listner, err := net.Listen(
		"tcp",
		viper.GetString("addr")+":"+viper.GetString("port"),
	)
	if err != nil {
		log.Println("Listen:", err)
		return
	}

	port := discovery.Port(listner.Addr())
	password := crypto.Sha(viper.GetString("dPass"), 10)
	message := []byte(fmt.Sprintf(
		"%s:%s",
		password,
		port,
	))
	go discovery.Broadcast(
		viper.GetInt("int"),
		viper.GetString("dKey"),
		viper.GetString("dAddr"),
		viper.GetString("dPort"),
		message,
	)

	err = http.Serve(listner, mux)
	if err != nil {
		log.Println("Serve: ", err)
		return
	}
}