Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created May 30, 2019 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/3f899e3cab2294f335a8a8c5da88b129 to your computer and use it in GitHub Desktop.
Save parzibyte/3f899e3cab2294f335a8a8c5da88b129 to your computer and use it in GitHub Desktop.
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