websocket.go 471 B

1234567891011121314151617181920212223242526
  1. package main
  2. import (
  3. // "fmt"
  4. // "io"
  5. "log"
  6. "net/http"
  7. "github.com/gorilla/websocket"
  8. )
  9. var upgrader = websocket.Upgrader{
  10. ReadBufferSize: 1024,
  11. WriteBufferSize: 1024,
  12. CheckOrigin: func(r *http.Request) bool { return true },
  13. }
  14. func Upgrade(w http.ResponseWriter, r *http.Request) (*websocket.Conn, error) {
  15. conn, err := upgrader.Upgrade(w, r, nil)
  16. if err != nil {
  17. log.Println(err)
  18. return nil, err
  19. }
  20. return conn, nil
  21. }