Files
kalzu-value-store/server/routes.go
ryyst 8d6a280441 feat: complete issue #6 - implement feature toggle integration in routes
- Add conditional route registration based on feature toggles
- AuthEnabled now controls authentication/user management endpoints
- ClusteringEnabled controls member and Merkle tree endpoints
- RevisionHistoryEnabled controls history endpoints
- Feature toggles for RateLimitingEnabled and TamperLoggingEnabled were already implemented

This completes issue #6 allowing flexible deployment scenarios by disabling
unnecessary features and their associated endpoints.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-20 23:50:58 +03:00

62 lines
2.6 KiB
Go

package server
import (
"github.com/gorilla/mux"
)
// setupRoutes configures all HTTP routes and their handlers
func (s *Server) setupRoutes() *mux.Router {
router := mux.NewRouter()
// Health endpoint (always available)
router.HandleFunc("/health", s.healthHandler).Methods("GET")
// KV endpoints (always available - see issue #5 for anonymous access control)
router.HandleFunc("/kv/{path:.+}", s.getKVHandler).Methods("GET")
router.HandleFunc("/kv/{path:.+}", s.putKVHandler).Methods("PUT")
router.HandleFunc("/kv/{path:.+}", s.deleteKVHandler).Methods("DELETE")
// Member endpoints (available when clustering is enabled)
if s.config.ClusteringEnabled {
router.HandleFunc("/members/", s.getMembersHandler).Methods("GET")
router.HandleFunc("/members/join", s.joinMemberHandler).Methods("POST")
router.HandleFunc("/members/leave", s.leaveMemberHandler).Methods("DELETE")
router.HandleFunc("/members/gossip", s.gossipHandler).Methods("POST")
router.HandleFunc("/members/pairs_by_time", s.pairsByTimeHandler).Methods("POST")
// Merkle Tree endpoints (clustering feature)
router.HandleFunc("/merkle_tree/root", s.getMerkleRootHandler).Methods("GET")
router.HandleFunc("/merkle_tree/diff", s.getMerkleDiffHandler).Methods("POST")
router.HandleFunc("/kv_range", s.getKVRangeHandler).Methods("POST")
}
// Authentication and user management endpoints (available when auth is enabled)
if s.config.AuthEnabled {
// User Management endpoints
router.HandleFunc("/api/users", s.createUserHandler).Methods("POST")
router.HandleFunc("/api/users/{uuid}", s.getUserHandler).Methods("GET")
router.HandleFunc("/api/users/{uuid}", s.updateUserHandler).Methods("PUT")
router.HandleFunc("/api/users/{uuid}", s.deleteUserHandler).Methods("DELETE")
// Group Management endpoints
router.HandleFunc("/api/groups", s.createGroupHandler).Methods("POST")
router.HandleFunc("/api/groups/{uuid}", s.getGroupHandler).Methods("GET")
router.HandleFunc("/api/groups/{uuid}", s.updateGroupHandler).Methods("PUT")
router.HandleFunc("/api/groups/{uuid}", s.deleteGroupHandler).Methods("DELETE")
// Token Management endpoints
router.HandleFunc("/api/tokens", s.createTokenHandler).Methods("POST")
}
// Revision History endpoints (available when revision history is enabled)
if s.config.RevisionHistoryEnabled {
router.HandleFunc("/api/data/{key}/history", s.getRevisionHistoryHandler).Methods("GET")
router.HandleFunc("/api/data/{key}/history/{revision}", s.getSpecificRevisionHandler).Methods("GET")
}
// Backup Status endpoint (always available if backup is enabled)
router.HandleFunc("/api/backup/status", s.getBackupStatusHandler).Methods("GET")
return router
}