feat(servers): implement saervers monitoring
This commit is contained in:
22
internal/api/server_handler.go
Normal file
22
internal/api/server_handler.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"gitea.mrixs.me/minecraft-platform/backend/internal/database"
|
||||
)
|
||||
|
||||
type ServerHandler struct {
|
||||
Repo *database.ServerRepository
|
||||
}
|
||||
|
||||
func (h *ServerHandler) GetServers(w http.ResponseWriter, r *http.Request) {
|
||||
servers, err := h.Repo.GetAllWithStatus(r.Context())
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to get servers", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(servers)
|
||||
}
|
||||
Reference in New Issue
Block a user