, - string, /. , . ( , - , .)
- . , . ( , , ). , "object like". ( , , .)
type echoStuff string
var hey echoStuff = "Hey!"
http.Handle("/", websocket.Handler(hey.EchoServer))
err := http.ListenAndServe(":8081", nil)
CheckError(err)
func (msg echoStuff) Echoserver(ws *websocket.Conn) {
fmt.Println("Client Connected")
_ := websocket.JSON.Send(ws, msg);
}
- . , " ". (- . , .)
func WebSocketServer() {
http.Handle("/", echoHandler("Hey!"))
err := http.ListenAndServe(":8081", nil)
CheckError(err)
}
func echoHandler(msg string) websocket.Handler {
return func(ws *Conn) {
Echoserver(ws, msg)
}
}