34 lines
1.4 KiB
Go
34 lines
1.4 KiB
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
)
|
|
|
|
// ResponseHandle is a function that middleware call in case of stop chain
|
|
type ResponseHandle func(w http.ResponseWriter, r *http.Request, err error)
|
|
|
|
// RespondWithBadRequest is a default bad request response handler
|
|
func RespondWithBadRequest(w http.ResponseWriter, _ *http.Request, _ error) {
|
|
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
|
}
|
|
|
|
// RespondWithUnauthorized is a default unathorized response handler
|
|
func RespondWithUnauthorized(w http.ResponseWriter, _ *http.Request, _ error) {
|
|
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
|
|
}
|
|
|
|
// RespondWithTooManyRequests is a default too many requests response handler
|
|
func RespondWithTooManyRequests(w http.ResponseWriter, _ *http.Request, _ error) {
|
|
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
|
|
}
|
|
|
|
// RespondWithInternalServerError is a default internal server error response handler
|
|
func RespondWithInternalServerError(w http.ResponseWriter, _ *http.Request, _ error) {
|
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
|
}
|
|
|
|
// RespondWithTimeout is a default gateway timeout response handler
|
|
func RespondWithGatewayTimeout(w http.ResponseWriter, _ *http.Request, _ error) {
|
|
http.Error(w, http.StatusText(http.StatusGatewayTimeout), http.StatusGatewayTimeout)
|
|
}
|