示例#1
0
func main() {
	flag.Parse()
	goquic.SetLogLevel(logLevel)

	useEncryption := false
	if len(cert) > 0 && len(key) > 0 {
		useEncryption = true
	}

	scheme := "http"
	if useEncryption {
		scheme = "https"
	}
	log.Printf("About to listen on %d. Go to %s://127.0.0.1:%d/", port, scheme, port)
	portStr := fmt.Sprintf(":%d", port)

	http.HandleFunc("/", httpHandler)
	http.Handle("/files/", http.StripPrefix("/files/", http.FileServer(http.Dir(serveRoot))))

	var err error

	if useEncryption {
		err = gospdyquic.ListenAndServeSecure(portStr, cert, key, numOfServers, nil)
	} else {
		err = gospdyquic.ListenAndServe(portStr, numOfServers, nil)
	}

	if err != nil {
		log.Fatal(err)
	}
}
示例#2
0
func main() {
	flag.Parse()
	goquic.SetLogLevel(logLevel)

	if flag.NArg() != 1 {
		flag.Usage()
		return
	}

	useEncryption := false
	if len(cert) > 0 && len(key) > 0 {
		useEncryption = true
	}
	proxyUrl := flag.Arg(0)

	scheme := "http"
	if useEncryption {
		scheme = "https"
	}
	log.Printf("About to listen on %d. Go to %s://127.0.0.1:%d/", port, scheme, port)
	portStr := fmt.Sprintf(":%d", port)

	parsedUrl, err := url.Parse(proxyUrl)
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("Starting reverse proxy for backend URL: %v", parsedUrl)

	if useEncryption {
		err = gospdyquic.ListenAndServeSecure(portStr, cert, key, numOfServers, httputil.NewSingleHostReverseProxy(parsedUrl))
	} else {
		err = gospdyquic.ListenAndServe(portStr, numOfServers, httputil.NewSingleHostReverseProxy(parsedUrl))
	}
	if err != nil {
		log.Fatal(err)
	}
}