added support for WS, add config supports limiting max

incorrect_closing_investigation
Evgeny Kovalev 2 years ago
parent 27601a61ff
commit d42b596bf0
  1. 2
      go.mod
  2. 3
      internal/config/config.go
  3. 35
      internal/server/server.go

@ -4,4 +4,4 @@ go 1.17
require github.com/xlab/closer v1.1.0
require github.com/cristalhq/aconfig v0.18.3 // indirect
require github.com/gorilla/websocket v1.5.0

@ -12,6 +12,9 @@ const ConfigPath string = "config.json"
type S_Config struct {
Address string `json:"Address"`
AdminSecret string `json:"AdminSecret"`
MaxLobbies int `json:"MaxLobbies"`
MaxPlayers int `json:"MaxPlayers"`
}
var Config S_Config

@ -5,14 +5,49 @@ import (
"fmt"
"log"
"net/http"
"github.com/gorilla/websocket"
)
type Health struct {
Health string `json:"Health"`
Lobbies int `json:"Lobbies"`
}
func health(w http.ResponseWriter, r *http.Request) {
}
func index(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "index")
}
func wsEndpoint(w http.ResponseWriter, r *http.Request) {
var upgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
}
conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
log.Println(r.RemoteAddr)
log.Println(err)
return
}
for {
messageType, p, err := conn.ReadMessage()
if err != nil {
log.Println(err)
return
}
if err := conn.WriteMessage(messageType, p); err != nil {
log.Println(err)
return
}
}
fmt.Fprintf(w, "hello")
}

Loading…
Cancel
Save