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.2 KiB
Go

12 months ago
package api
import (
"encoding/gob"
"net/http"
"time"
"github.com/go-co-op/gocron"
)
11 months ago
type Server struct {
Debug bool
}
var (
scheduler = gocron.NewScheduler(time.UTC)
)
11 months ago
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
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
}
}
gob.Register([]interface{}{})
gob.Register(map[string]interface{}{})
11 months ago
switch r.URL.Path {
case "/account/info":
s.HandleAccountInfo(w, r)
case "/account/register":
s.HandleAccountRegister(w, r)
case "/account/login":
s.HandleAccountLogin(w, r)
case "/account/logout":
s.HandleAccountLogout(w, r)
case "/savedata/get":
s.HandleSavedataGet(w, r)
case "/savedata/update":
s.HandleSavedataUpdate(w, r)
case "/savedata/delete":
s.HandleSavedataDelete(w, r)
case "/savedata/clear":
s.HandleSavedataClear(w, r)
case "/daily/seed":
s.HandleSeed(w, r)
11 months ago
}
}
12 months ago
// auth
type GenericAuthRequest struct {
Username string `json:"username"`
Password string `json:"password"`
}
type GenericAuthResponse struct {
Token string `json:"token"`
}