Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
package main
import (
type Proxy struct {
proxy *httputil.ReverseProxy
func NewProxy(targetUrl string) Proxy {
u, _ := url.Parse(targetUrl)
return Proxy{
proxy: httputil.NewSingleHostReverseProxy(u),
func (p Proxy) handle(w http.ResponseWriter, r *http.Request) {
// We may want to attach metadata to request header
r.Header.Add("Header1", "bar")
r.Header.Set("Header2", "foo")
p.proxy.ServeHTTP(w, r)
func main() {
proxy := NewProxy("")
http.HandleFunc("/", proxy.handle)
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatalf("Error starting http server: %v", err)