chourobin
9/4/2012 - 9:12 PM

Simple reverse proxy in Go.

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")
}