- Removed all duplicate Server methods from main.go (630 lines) - Fixed import conflicts and unused imports - main.go reduced from 3,298 to 340 lines (89% reduction) - Clean modular structure with server package handling all server functionality - Achieved clean build with no compilation errors 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
55 lines
2.3 KiB
Go
55 lines
2.3 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
|
|
router.HandleFunc("/health", s.healthHandler).Methods("GET")
|
|
|
|
// KV endpoints
|
|
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
|
|
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") // Still available for clients
|
|
|
|
// Merkle Tree endpoints
|
|
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") // New endpoint for fetching ranges
|
|
|
|
// 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
|
|
router.HandleFunc("/api/data/{key}/history", s.getRevisionHistoryHandler).Methods("GET")
|
|
router.HandleFunc("/api/data/{key}/history/{revision}", s.getSpecificRevisionHandler).Methods("GET")
|
|
|
|
// Backup Status endpoint
|
|
router.HandleFunc("/api/backup/status", s.getBackupStatusHandler).Methods("GET")
|
|
|
|
return router
|
|
}
|