Server.go
package main
import (
"fmt"
"golang.org/x/net/websocket"
"html/template"
"io"
"log"
"net/http"
"time"
)
var (
msgCh chan string
conns map[*websocket.Conn]string
Names = []string{
"Ulmer","zoe","Charlotte","Dylan","Edward","Freya",
"Gale","Mollie","Andrew","Charlotte","Elsa"}
msgCache = []string{
}
CacheLen = 20
)
func main() {
msgCh = make(chan string, 1)
conns = make(map[*websocket.Conn]string)
http.HandleFunc("/", homeHandler)
//http.HandleFunc("/ws", wsHandler)
http.Handle("/ws", websocket.Handler(wsHandler))
go writer()
log.Fatal(http.ListenAndServe(":9999", nil))
}
func homeHandler(w http.ResponseWriter, r *http.Request) {
tmp, err := template.ParseFiles("./client.html")
if err != nil {
log.Fatal(err)
}
err = tmp.ExecuteTemplate(w, "home", r.Host)
if err != nil {
log.Fatal(err)
}
}
func wsHandler(ws *websocket