go 语言 http请求转发

package main
 
import (
	"fmt"
	"io"

	"net/http"
	"net/http/httputil"
	"net/url"
	
)
func ServeHTTP(w http.ResponseWriter, r *http.Request) {
	if r.RequestURI == "/favicon.ico" {
		io.WriteString(w, "Request path Error")
		return
	}
	remote, err := url.Parse("http://" + "47.92.84.22")
	if err != nil {
		fmt.Println("json err:", err)
	 }
	proxy := httputil.NewSingleHostReverseProxy(remote)
	proxy.ServeHTTP(w, r)
	}
	func main() {
		http.HandleFunc("/", ServeHTTP)
		http.ListenAndServe(":8085", nil)
	}
发布了455 篇原创文章 · 获赞 77 · 访问量 131万+

猜你喜欢

转载自blog.csdn.net/az44yao/article/details/103537108