This commit is contained in:
Florian Hoss 2023-07-04 11:51:13 +02:00
commit f90fdc0598
99 changed files with 15260 additions and 0 deletions

36
websocket/websocket.go Normal file
View 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
}
}
}