-
-
Save parzibyte/3f899e3cab2294f335a8a8c5da88b129 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func middlewareEliminar(siguienteManejador http.Handler) http.Handler { | |
return http.HandlerFunc( | |
func(respuesta http.ResponseWriter, peticion *http.Request) { | |
// Si no llamamos a siguienteManejador, se detiene | |
// así que podemos aquí comprobar algo y detener determinada acción | |
// Por ejemplo, permitir solo si no son de tipo DELETE | |
if peticion.Method == http.MethodDelete { | |
http.Error(respuesta, "Permiso denegado", http.StatusForbidden) | |
} else { | |
// En caso de que sea permitida llamamos a siguienteManejador | |
// y le pasamos la respuesta con la petición | |
siguienteManejador.ServeHTTP(respuesta, peticion) | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment