Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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