Init
This commit is contained in:
commit
f90fdc0598
99 changed files with 15260 additions and 0 deletions
36
websocket/websocket.go
Normal file
36
websocket/websocket.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package websocket
|
||||
|
||||
import (
|
||||
"cafe/config"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
func inAllowedHosts(str string) bool {
|
||||
for _, a := range config.Cafe.AllowedHosts {
|
||||
if a == str {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var Upgrader = websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool {
|
||||
origin := r.Header.Get("Origin")
|
||||
return inAllowedHosts(origin)
|
||||
},
|
||||
ReadBufferSize: 1024,
|
||||
WriteBufferSize: 1024,
|
||||
}
|
||||
|
||||
func ReadPump(conn *websocket.Conn) {
|
||||
defer conn.Close()
|
||||
for {
|
||||
_, _, err := conn.ReadMessage()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue