Skip to content

Instantly share code, notes, and snippets.

@berkant
Last active Aug 30, 2018
Embed
What would you like to do?
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