Skip to content

Instantly share code, notes, and snippets.

@berkant
Last active August 30, 2018 14:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save berkant/27dc054171cfb8cd55da39c1694f6759 to your computer and use it in GitHub Desktop.
tr.wikipedia.org Reverse Proxy in Go
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