Skip to content

Instantly share code, notes, and snippets.

Forked from JalfResi/revprox.go
Created May 27, 2023 19:33
  • 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 icebreaker/5ccf872d27ae97d2daa2a66792ba5ed4 to your computer and use it in GitHub Desktop.
Simple reverse proxy in Go
package main
func main() {
remote, err := url.Parse("")
if err != nil {
handler := func(p *httputil.ReverseProxy) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
r.Host = remote.Host
w.Header().Set("X-Ben", "Rad")
p.ServeHTTP(w, r)
proxy := httputil.NewSingleHostReverseProxy(remote)
http.HandleFunc("/", handler(proxy))
err = http.ListenAndServe(":8080", nil)
if err != nil {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment