Skip to content

Instantly share code, notes, and snippets.

@anandkunal
Created September 4, 2012 21:12
Show Gist options
  • Save anandkunal/3626555 to your computer and use it in GitHub Desktop.
Save anandkunal/3626555 to your computer and use it in GitHub Desktop.
Simple reverse proxy in Go.
package main
import (
"log"
"net/http"
"net/http/httputil"
"net/url"
)
func main() {
u, err := url.Parse("http://www.cnn.com")
if err != nil {
log.Fatal(err)
}
reverse_proxy := httputil.NewSingleHostReverseProxy(u)
http.Handle("/", reverse_proxy)
if err = http.ListenAndServe(":8080", nil); err != nil {
log.Fatal(err)
}
log.Println("Server started")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment