Backend: API handlers, WebSocket manager, K8s client, CRDT, auth
This commit is contained in:
20
server/internal/ws/logs.go
Normal file
20
server/internal/ws/logs.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package ws
|
||||
|
||||
import (
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
func LogsHandler(conn *websocket.Conn, r *http.Request) error {
|
||||
// Extract pod and namespace from query params
|
||||
pod := r.URL.Query().Get("pod")
|
||||
namespace := r.URL.Query().Get("ns")
|
||||
|
||||
if pod == "" || namespace == "" {
|
||||
return websocket.CloseBadRequest
|
||||
}
|
||||
|
||||
// TODO: Implement logs streaming
|
||||
// This will connect to k8s logs API and stream logs via WebSocket
|
||||
|
||||
return nil
|
||||
}
|
||||
41
server/internal/ws/manager.go
Normal file
41
server/internal/ws/manager.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package ws
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"krates/server/internal/crdt"
|
||||
)
|
||||
|
||||
type HandlerFunc func(*websocket.Conn, *http.Request) error
|
||||
|
||||
type WebSocketManager struct {
|
||||
crdtProvider *crdt.Provider
|
||||
upgrader *websocket.Upgrader
|
||||
}
|
||||
|
||||
func NewManager(crdtProvider *crdt.Provider) *WebSocketManager {
|
||||
return &WebSocketManager{
|
||||
crdtProvider: crdtProvider,
|
||||
upgrader: &websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool {
|
||||
return true
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (m *WebSocketManager) WithWebSocket(handler HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
conn, err := m.upgrader.Upgrade(w, r, nil)
|
||||
if err != nil {
|
||||
http.Error(w, "WebSocket upgrade failed", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
if err := handler(conn, r); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
20
server/internal/ws/shell.go
Normal file
20
server/internal/ws/shell.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package ws
|
||||
|
||||
import (
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
func ShellHandler(conn *websocket.Conn, r *http.Request) error {
|
||||
// Extract pod and namespace from query params
|
||||
pod := r.URL.Query().Get("pod")
|
||||
namespace := r.URL.Query().Get("ns")
|
||||
|
||||
if pod == "" || namespace == "" {
|
||||
return websocket.CloseBadRequest
|
||||
}
|
||||
|
||||
// TODO: Implement shell connection
|
||||
// This will connect to k8s exec API and proxy WebSocket ↔ k8s stream
|
||||
|
||||
return nil
|
||||
}
|
||||
12
server/internal/ws/sync.go
Normal file
12
server/internal/ws/sync.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package ws
|
||||
|
||||
import (
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
func SyncHandler(conn *websocket.Conn, r *http.Request) error {
|
||||
// TODO: Implement CRDT sync
|
||||
// This will handle Yjs sync messages for shared workspace state
|
||||
|
||||
return nil
|
||||
}
|
||||
12
server/internal/ws/watch.go
Normal file
12
server/internal/ws/watch.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package ws
|
||||
|
||||
import (
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
func WatchHandler(conn *websocket.Conn, r *http.Request) error {
|
||||
// TODO: Implement resource watch streaming
|
||||
// This will watch K8s resources and broadcast changes to clients
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user