gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/net/websocket/examplehandler_test.go (about) 1 // Copyright 2012 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package websocket_test 6 7 import ( 8 "io" 9 10 http "gitee.com/ks-custle/core-gm/gmhttp" 11 12 "gitee.com/ks-custle/core-gm/net/websocket" 13 ) 14 15 // Echo the data received on the WebSocket. 16 func EchoServer(ws *websocket.Conn) { 17 io.Copy(ws, ws) 18 } 19 20 // This example demonstrates a trivial echo server. 21 func ExampleHandler() { 22 http.Handle("/echo", websocket.Handler(EchoServer)) 23 err := http.ListenAndServe(":12345", nil) 24 if err != nil { 25 panic("ListenAndServe: " + err.Error()) 26 } 27 }