Last active
August 30, 2018 14:15
-
-
Save berkant/27dc054171cfb8cd55da39c1694f6759 to your computer and use it in GitHub Desktop.
tr.wikipedia.org Reverse Proxy in Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"net/http" | |
"net/http/httputil" | |
"net/url" | |
) | |
var ( | |
origin, _ = url.Parse("https://tr.wikipedia.org") | |
) | |
func main() { | |
originProxy := httputil.NewSingleHostReverseProxy(origin) | |
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
if r.URL.Path == "/" { | |
http.Redirect(w, r, "/wiki/Anasayfa", http.StatusMovedPermanently) | |
return | |
} | |
r.Host = origin.Host | |
originProxy.ServeHTTP(w, r) | |
}) | |
log.Fatal(http.ListenAndServe(":8080", nil)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment