- Introduced .editorconfig for consistent coding styles across the project. - Added .golangci.yml for Go linting configuration. - Updated AGENTS.md to clarify project structure and components. - Enhanced CONTRIBUTING.md with Makefile usage for common tasks. - Updated Dockerfiles to use Go 1.24 and improved build instructions. - Refined README.md and deployment documentation for clarity. - Added testing documentation in testing.md for backend and frontend tests. - Introduced Makefile for streamlined development commands and tasks.
76 lines
1.6 KiB
Go
76 lines
1.6 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
// APIRouter routes /map/api/* requests to the appropriate handler.
|
|
func (h *Handlers) APIRouter(rw http.ResponseWriter, req *http.Request) {
|
|
path := strings.TrimPrefix(req.URL.Path, "/map/api")
|
|
path = strings.TrimPrefix(path, "/")
|
|
|
|
switch path {
|
|
case "config":
|
|
h.APIConfig(rw, req)
|
|
return
|
|
case "v1/characters":
|
|
h.APIGetChars(rw, req)
|
|
return
|
|
case "v1/markers":
|
|
h.APIGetMarkers(rw, req)
|
|
return
|
|
case "maps":
|
|
h.APIGetMaps(rw, req)
|
|
return
|
|
case "setup":
|
|
h.APISetup(rw, req)
|
|
return
|
|
case "login":
|
|
h.APILogin(rw, req)
|
|
return
|
|
case "logout":
|
|
h.APILogout(rw, req)
|
|
return
|
|
case "me":
|
|
h.APIMe(rw, req)
|
|
return
|
|
case "me/tokens":
|
|
h.APIMeTokens(rw, req)
|
|
return
|
|
case "me/password":
|
|
h.APIMePassword(rw, req)
|
|
return
|
|
}
|
|
|
|
switch {
|
|
case path == "oauth/providers":
|
|
h.APIOAuthProviders(rw, req)
|
|
return
|
|
case strings.HasPrefix(path, "oauth/"):
|
|
rest := strings.TrimPrefix(path, "oauth/")
|
|
parts := strings.SplitN(rest, "/", 2)
|
|
if len(parts) != 2 {
|
|
JSONError(rw, http.StatusNotFound, "not found", "NOT_FOUND")
|
|
return
|
|
}
|
|
provider := parts[0]
|
|
action := parts[1]
|
|
switch action {
|
|
case "login":
|
|
h.APIOAuthLogin(rw, req, provider)
|
|
case "callback":
|
|
h.APIOAuthCallback(rw, req, provider)
|
|
default:
|
|
JSONError(rw, http.StatusNotFound, "not found", "NOT_FOUND")
|
|
}
|
|
return
|
|
case strings.HasPrefix(path, "admin/"):
|
|
adminPath := strings.TrimPrefix(path, "admin/")
|
|
h.APIAdminRoute(rw, req, adminPath)
|
|
return
|
|
}
|
|
|
|
JSONError(rw, http.StatusNotFound, "not found", "NOT_FOUND")
|
|
}
|