Source

bereal / bereal.go

package main

import (
	"io"
	"log"
	"net/http"
	"net/http/httputil"
	"net/url"
	"code.google.com/p/go.net/websocket"
)

const (
	STATIC_ROOT string = "/home/yml/Developments/python/bereal/var/static"
	STATIC_URL string = "/static"
)

func EchoServer(ws *websocket.Conn) {
    log.Println("got something")
    io.Copy(ws, ws)
}

func main() {
	log.Println("start bereal go server")
	dstUrl, err := url.Parse("http://127.0.0.1:8000")
	if err != nil {
	  log.Fatal(err)
	}

	http.Handle("/ws", websocket.Handler(EchoServer))
	http.Handle(STATIC_URL, http.FileServer(http.Dir(STATIC_ROOT)))
	reverse_proxy := httputil.NewSingleHostReverseProxy(dstUrl)
	http.Handle("/", reverse_proxy)

	if err = http.ListenAndServe(":8080", nil); err != nil {
	  log.Fatal(err)
	}
}