mirror of
https://github.com/ilanyu/ReverseProxy.git
synced 2024-04-21 12:41:56 +00:00
24 lines
483 B
Go
24 lines
483 B
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
"net/http/httputil"
|
|
"log"
|
|
)
|
|
|
|
type handle struct {
|
|
reverseProxy string
|
|
}
|
|
|
|
func (this *handle) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
remote, err := url.Parse(this.reverseProxy)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
proxy := httputil.NewSingleHostReverseProxy(remote)
|
|
r.Host = remote.Host
|
|
proxy.ServeHTTP(w, r)
|
|
log.Println(r.RemoteAddr + " " + r.Method + " " + r.URL.String() + " " + r.Proto + " " + r.UserAgent())
|
|
}
|