Files
viettranx e1cb5c411b refactor(http): move gateway token to package-level auth state
Replace per-handler `token string` field with package-level
`pkgGatewayToken` via `InitGatewayToken()`, matching the existing
pattern for `pkgAPIKeyCache`, `pkgOwnerIDs`, etc.

- Remove `token` from ~30 HTTP handler structs and constructors
- Simplify `requireAuth(minRole, next)` signature (was 3 params)
- Simplify `resolveAuth(r)` signature (was 2 params)
- Rename `resolveAuthBearer` → `resolveAuthWithBearer` (clearer)
- Add `store.WithRole()`/`RoleFromContext()` to propagate caller
  role through context
- Inject role into context in `requireAuth` and `requireAuthBearer`
2026-03-23 22:57:26 +07:00

35 lines
1.4 KiB
Go

package http
import (
"net/http"
"github.com/nextlevelbuilder/goclaw/internal/store"
)
// MemoryHandler handles memory document management endpoints.
type MemoryHandler struct {
store store.MemoryStore
}
// NewMemoryHandler creates a handler for memory management endpoints.
func NewMemoryHandler(s store.MemoryStore) *MemoryHandler {
return &MemoryHandler{store: s}
}
// RegisterRoutes registers all memory routes on the given mux.
func (h *MemoryHandler) RegisterRoutes(mux *http.ServeMux) {
mux.HandleFunc("GET /v1/memory/documents", h.auth(h.handleListAllDocuments))
mux.HandleFunc("GET /v1/agents/{agentID}/memory/documents", h.auth(h.handleListDocuments))
mux.HandleFunc("GET /v1/agents/{agentID}/memory/documents/{path...}", h.auth(h.handleGetDocument))
mux.HandleFunc("PUT /v1/agents/{agentID}/memory/documents/{path...}", h.auth(h.handlePutDocument))
mux.HandleFunc("DELETE /v1/agents/{agentID}/memory/documents/{path...}", h.auth(h.handleDeleteDocument))
mux.HandleFunc("GET /v1/agents/{agentID}/memory/chunks", h.auth(h.handleListChunks))
mux.HandleFunc("POST /v1/agents/{agentID}/memory/index", h.auth(h.handleIndexDocument))
mux.HandleFunc("POST /v1/agents/{agentID}/memory/index-all", h.auth(h.handleIndexAll))
mux.HandleFunc("POST /v1/agents/{agentID}/memory/search", h.auth(h.handleSearch))
}
func (h *MemoryHandler) auth(next http.HandlerFunc) http.HandlerFunc {
return requireAuth("", next)
}