From 6245310290a3e3794a1324acd806b3d7ce5cef01 Mon Sep 17 00:00:00 2001 From: eeckert Date: Tue, 12 Dec 2023 13:29:55 -0700 Subject: [PATCH] add catchall --- main/main.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/main/main.go b/main/main.go index 7c6dce8..2a70b81 100644 --- a/main/main.go +++ b/main/main.go @@ -27,18 +27,29 @@ func HealthCheck(resp http.ResponseWriter, request *http.Request) { resp.Write([]byte(MessageText)) } +func CatchError(resp http.ResponseWriter, request *http.Request) { + var LogText = "got bad request from " + request.RemoteAddr + ". Method: " + request.Method + fmt.Println(http.StatusBadRequest, LogText) + var MessageText = "Invalid Request, please read the docs..." + resp.WriteHeader(http.StatusBadRequest) + resp.Write([]byte(MessageText)) + +} + func handleRequests() { // Start new Mux router mainrouter := mux.NewRouter().StrictSlash(true) mainrouter.HandleFunc("/", readDataStream).Methods("POST") mainrouter.HandleFunc("/healthcheck", HealthCheck).Methods("GET") + mainrouter.HandleFunc("/", CatchError) log.Fatal(http.ListenAndServe(":10000", mainrouter)) } func main() { - fmt.Println("MPE x Egnyte x PowerApps - Mux Router") + var t = time.Now().String() + fmt.Println("MPE x Egnyte x PowerApps - Mux Router starting: " + t) handleRequests() }