add catchall

This commit is contained in:
Erik Eckert 2023-12-12 13:29:55 -07:00
parent 4573bb5ba3
commit 6245310290

View File

@ -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()
}