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.

68 lines
1.3 KiB
Go

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