25 lines
642 B
Go
25 lines
642 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
// AreProcessesUp sends back status of watched processes.
|
|
func AreProcessesUp(processes *[]Process) func(http.ResponseWriter, *http.Request) {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodGet {
|
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
|
w.Header().Add("Allow", "GET")
|
|
return
|
|
}
|
|
|
|
w.Header().Add("Content-Type", "application/json")
|
|
if err := json.NewEncoder(w).Encode(GetProcessesState(processes)); err != nil {
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
log.Printf("Failed to encode a process list: %s\n", err)
|
|
}
|
|
}
|
|
}
|