raid.go 964 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package main
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "strings"
  6. "imuslab.com/bokofs/bokofsd/mod/utils"
  7. )
  8. /*
  9. raid.go
  10. This file handles the RAID management and monitoring API routing
  11. */
  12. func HandleRAIDCalls() http.Handler {
  13. return http.StripPrefix("/raid/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  14. pathParts := strings.Split(r.URL.Path, "/")
  15. switch pathParts[0] {
  16. case "list":
  17. // List all RAID devices
  18. raidManager.HandleListRaidDevices(w, r)
  19. return
  20. case "sync":
  21. // Get the RAID sync state, require "dev=md0" as a query parameter
  22. raidManager.HandleGetRAIDSyncState(w, r)
  23. return
  24. case "test":
  25. ss, err := raidManager.GetSyncStates()
  26. if err != nil {
  27. http.Error(w, "Internal Server Error", http.StatusInternalServerError)
  28. return
  29. }
  30. js, _ := json.Marshal(ss)
  31. utils.SendJSONResponse(w, string(js))
  32. return
  33. default:
  34. http.Error(w, "Not Found", http.StatusNotFound)
  35. return
  36. }
  37. }))
  38. }