You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rogueserver/api/generic.go

68 lines
1.3 KiB
Go

11 months ago
package api
import (
"encoding/gob"
"net/http"
)
11 months ago
type Server struct {
Debug bool
}
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
gob.Register([]interface{}{})
gob.Register(map[string]interface{}{})
11 months ago
if s.Debug {
w.Header().Set("Access-Control-Allow-Headers", "*")
w.Header().Set("Access-Control-Allow-Methods", "*")
w.Header().Set("Access-Control-Allow-Origin", "*")
11 months ago
if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
return
}
}
switch r.URL.Path {
case "/account/info":
7 months ago
s.handleAccountInfo(w, r)
11 months ago
case "/account/register":
7 months ago
s.handleAccountRegister(w, r)
11 months ago
case "/account/login":
7 months ago
s.handleAccountLogin(w, r)
11 months ago
case "/account/logout":
7 months ago
s.handleAccountLogout(w, r)
11 months ago
case "/game/playercount":
7 months ago
s.handlePlayerCountGet(w)
11 months ago
case "/savedata/get":
7 months ago
s.handleSavedataGet(w, r)
11 months ago
case "/savedata/update":
7 months ago
s.handleSavedataUpdate(w, r)
11 months ago
case "/savedata/delete":
7 months ago
s.handleSavedataDelete(w, r)
case "/savedata/clear":
7 months ago
s.handleSavedataClear(w, r)
case "/daily/seed":
7 months ago
s.handleSeed(w)
case "/daily/rankings":
7 months ago
s.handleRankings(w, r)
case "/daily/rankingpagecount":
7 months ago
s.handleRankingPageCount(w, r)
11 months ago
}
}
11 months ago
// auth
type GenericAuthRequest struct {
Username string `json:"username"`
Password string `json:"password"`
}
type GenericAuthResponse struct {
Token string `json:"token"`
}