示例#1
0
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
func Run() {
	addr := viper.GetString("addr")
	port := viper.GetString("port")
	if viper.GetString("send") != "" ||
		viper.GetString("online") != "" {
		client := &BaseClient{}
		client.interval = viper.GetInt("int")
		if viper.GetString("key") != "" {
			crypto.LoadKey(client, viper.GetString("key"), "public")
		}
		if viper.GetString("send") != "" {
			client.Send(addr, port, []byte(viper.GetString("send")))
		} else if viper.GetString("online") != "" {
			client.Online(addr, port, []byte(viper.GetString("online")))
		}
	} else {
		service := &BaseService{}
		if viper.GetString("key") != "" {
			crypto.LoadKey(service, viper.GetString("key"), "private")
		}
		Listen(service, addr, port)
	}
}
示例#3
0
func Broadcast(interval int, keyFile, addr, port string, message []byte) {
	client := NewBaseClient()
	client.interval = interval
	crypto.LoadKey(
		client,
		keyFile,
		"public",
	)
	client.Online(
		addr,
		port,
		message,
	)
}