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) } }
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 } }