MCPcopy Create free account
hub / github.com/cronitorio/cronitor-cli / handleGetCrontabs

Function handleGetCrontabs

cmd/dash.go:2383–2406  ·  view source on GitHub ↗

handleGetCrontabs handles GET requests for crontabs

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

2381
2382// handleGetCrontabs handles GET requests for crontabs
2383func handleGetCrontabs(w http.ResponseWriter, r *http.Request) {
2384 if r.Method != "GET" {
2385 http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
2386 return
2387 }
2388
2389 // Read all crontabs
2390 var crontabs []*lib.Crontab
2391 crontabs, err := lib.GetAllCrontabs(parseUsers())
2392 if err != nil {
2393 http.Error(w, err.Error(), http.StatusInternalServerError)
2394 return
2395 }
2396
2397 // Parse each crontab to ensure lines are loaded
2398 for _, crontab := range crontabs {
2399 if len(crontab.Lines) == 0 && crontab.Exists() {
2400 crontab.Parse(true)
2401 }
2402 }
2403
2404 w.Header().Set("Content-Type", "application/json")
2405 json.NewEncoder(w).Encode(crontabs)
2406}
2407
2408// handlePostCrontabs handles POST requests to create a new crontab
2409func handlePostCrontabs(w http.ResponseWriter, r *http.Request) {

Callers 1

handleCrontabsFunction · 0.85

Calls 5

GetAllCrontabsFunction · 0.92
parseUsersFunction · 0.85
ErrorMethod · 0.80
ExistsMethod · 0.80
ParseMethod · 0.80

Tested by

no test coverage detected