From fc89bcdd31de82eecfaf33a5f4c475b36a369974 Mon Sep 17 00:00:00 2001 From: agerho000 Date: Mon, 30 Nov 2020 04:17:55 +0000 Subject: [PATCH] Fixed type errors --- handlers/handlers.go | 10 ++++++---- handlers/services.go | 12 +++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/handlers/handlers.go b/handlers/handlers.go index b9fd596d..1f0ef42d 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -3,13 +3,14 @@ package handlers import ( "encoding/json" "fmt" - "github.com/statping/statping/types/errors" "html/template" "net/http" "path" "time" "github.com/statping/statping/source" + "github.com/statping/statping/types/errors" + "github.com/statping/statping/types/services" "github.com/statping/statping/utils" ) @@ -212,18 +213,19 @@ func returnJson(d interface{}, w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(d) } -func returnResponseCode(s *Service, w http.ResponseWriter, r *http.Request) { +func returnResponseCode(s *services.Service, w http.ResponseWriter, r *http.Request) { // Go does not currently // support sending user-defined 1xx informational headers, // with the exception of 100-continue response header that the // Server sends automatically when the Request.Body is read. // https://golang.org/src/net/http/server.go?s=3003:5866#L150 - if LastStatusCode >= 100 { + + if s.LastStatusCode >= 100 { w.WriteHeader(s.LastStatusCode) w.Write([]byte(s.DownText)) return } - + w.WriteHeader(http.StatusTeapot) w.Write([]byte("☄ Last Status Code Not Set!")) } diff --git a/handlers/services.go b/handlers/services.go index 8e77f5a9..5fcd2a6a 100644 --- a/handlers/services.go +++ b/handlers/services.go @@ -1,6 +1,8 @@ package handlers import ( + "net/http" + "github.com/gorilla/mux" "github.com/statping/statping/database" "github.com/statping/statping/types/errors" @@ -8,7 +10,6 @@ import ( "github.com/statping/statping/types/hits" "github.com/statping/statping/types/services" "github.com/statping/statping/utils" - "net/http" ) type serviceOrder struct { @@ -317,12 +318,13 @@ func apiServiceHitsHandler(r *http.Request) interface{} { return hts } -func apiServiceResponseCodeHandler(w http.ResponseWriter, r *http.Request) interface{} { +func apiServiceResponseCodeHandler(w http.ResponseWriter, r *http.Request) { service, err := findService(r) if err != nil { - return err + sendErrorJson(err, w, r) + return } - - return returnResponseCode(service, w, r) + + returnResponseCode(service, w, r) }