Backend: API handlers, WebSocket manager, K8s client, CRDT, auth

This commit is contained in:
Hermes Agent
2026-06-16 08:53:24 -04:00
parent 33c6648b84
commit 27779ba26f
15 changed files with 427 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
package handlers
import (
"encoding/json"
"net/http"
)
type ClusterInfo struct {
Name string `json:"name"`
Version string `json:"version"`
Health bool `json:"health"`
ServerURL string `json:"server_url"`
}
func ClusterHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
cluster := ClusterInfo{
Name: "local",
Version: "v1.29.0",
Health: true,
ServerURL: "https://kubernetes.default.svc",
}
json.NewEncoder(w).Encode(cluster)
}

View File

@@ -0,0 +1,15 @@
package handlers
import (
"encoding/json"
"net/http"
)
type HealthResponse struct {
Status string `json:"status"`
}
func HealthHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(HealthResponse{Status: "ok"})
}

View File

@@ -0,0 +1,14 @@
package handlers
import (
"encoding/json"
"net/http"
)
func NamespacesHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
namespaces := []string{"default", "kube-system", "kube-public"}
json.NewEncoder(w).Encode(namespaces)
}

View File

@@ -0,0 +1,47 @@
package handlers
import (
"encoding/json"
"net/http"
)
type ResourceResponse struct {
Kind string `json:"kind"`
Name string `json:"name"`
Namespace string `json:"namespace"`
UID string `json:"uid"`
Labels map[string]string `json:"labels,omitempty"`
CreatedAt string `json:"created_at"`
}
func ResourcesHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
// Placeholder - will be implemented with actual K8s client
resources := []ResourceResponse{
{
Kind: "Namespace",
Name: "default",
Namespace: "",
UID: "ns-default",
CreatedAt: "2024-01-01T00:00:00Z",
},
}
json.NewEncoder(w).Encode(resources)
}
func ResourceHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
// Placeholder - will be implemented with actual K8s client
resource := ResourceResponse{
Kind: "Pod",
Name: "example-pod",
Namespace: "default",
UID: "pod-example",
CreatedAt: "2024-01-01T00:00:00Z",
}
json.NewEncoder(w).Encode(resource)
}

View File

@@ -0,0 +1,20 @@
package api
import (
"net/http"
"krates/server/internal/api/handlers"
)
func SetupRoutes() http.Handler {
mux := http.NewServeMux()
mux.HandleFunc("/health", handlers.HealthHandler)
mux.HandleFunc("/cluster", handlers.ClusterHandler)
mux.HandleFunc("/resources", handlers.ResourcesHandler)
mux.HandleFunc("/resources/", handlers.ResourcesHandler)
mux.HandleFunc("/resource/", handlers.ResourceHandler)
mux.HandleFunc("/namespaces", handlers.NamespacesHandler)
return mux
}