diff --git a/main.go b/main.go index a1b633e..e980e6d 100644 --- a/main.go +++ b/main.go @@ -87,7 +87,19 @@ func main() { } router := http.NewServeMux() - router.HandleFunc("/processes", AreProcessesUp(&conf.Processes)) + router.HandleFunc("/processes", 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(&conf.Processes)); err != nil { + w.WriteHeader(http.StatusInternalServerError) + log.Printf("Failed to encode a process list: %s\n", err) + } + }) srv := &http.Server{ Addr: conf.ListenAddress, @@ -127,20 +139,3 @@ func main() { } } } - -// 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) - } - } -}