handleGetCrontabs handles GET requests for crontabs
(w http.ResponseWriter, r *http.Request)
| 2381 | |
| 2382 | // handleGetCrontabs handles GET requests for crontabs |
| 2383 | func 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 |
| 2409 | func handlePostCrontabs(w http.ResponseWriter, r *http.Request) { |
no test coverage detected