github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/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 "github.com/hxx258456/ccgo/gmhttp"
    11  
    12  	"github.com/hxx258456/ccgo/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  }