add catchall
This commit is contained in:
parent
4573bb5ba3
commit
6245310290
13
main/main.go
13
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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user