Handling 404 better
package web
import (
- "fmt"
"net/http"
log "github.com/Sirupsen/logrus"
@@ -9,13 +8,20 @@ import (
"github.com/hellofresh/janus/pkg/response"
)
+// Home handler is just a nice home page message
func Home() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
- response.JSON(w, http.StatusOK, fmt.Sprintf("Welcome to Janus"))
+ response.JSON(w, http.StatusOK, "Welcome to Janus")
}
}
-// RecoveryHandler handler for the apis
+// NotFound handler is called when no route is matched
+func NotFound(w http.ResponseWriter, r *http.Request) {
+ notfoundError := errors.ErrRouteNotFound
+ response.JSON(w, notfoundError.Code, notfoundError)
+}
+
+// RecoveryHandler handler is used when a panic happens
func RecoveryHandler(w http.ResponseWriter, r *http.Request, err interface{}) {
switch internalErr := err.(type) {
case *errors.Error:
@@ -27,6 +33,7 @@ func RecoveryHandler(w http.ResponseWriter, r *http.Request, err interface{}) {
}
}
+// Heartbeat normally is used by the load balancers to identify if the application is alive
func Heartbeat() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
response.JSON(w, http.StatusOK, nil)
