package main import ( "fmt" "io" "net/http" "golang.org/x/net/websocket" ) func echoHandler(ws *websocket.Conn) { fmt.Println("echoHandler") io.Copy(ws, ws) } func main() { http.Handle("/echo", websocket.Handler(echoHandler)) http.HandleFunc("/", rootHandler) err := http.ListenAndServe(":8080", nil) if err != nil { panic("ListenAndServe: " + err.Error()) } } func errorHandler(w http.ResponseWriter, r *http.Request, status int) { w.WriteHeader(status) fmt.Println(status, r.URL.Path) } func rootHandler(w http.ResponseWriter, r *http.Request) { errorHandler(w, r, http.StatusNotFound) return }