github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/methodnotallowed/method_not_allowed_handler.go (about) 1 package methodnotallowed 2 3 import ( 4 "fmt" 5 "net/http" 6 7 "github.com/kyma-incubator/compass/components/director/internal/nsadapter/httputil" 8 ) 9 10 type methodNotAllowedHandler struct { 11 } 12 13 // CreateMethodNotAllowedHandler creates handler that responds when the endpoint is called with method that is not allowed 14 func CreateMethodNotAllowedHandler() methodNotAllowedHandler { 15 return methodNotAllowedHandler{} 16 } 17 18 // ServeHTTP handles the request 19 func (h methodNotAllowedHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { 20 httputil.RespondWithError(r.Context(), w, http.StatusMethodNotAllowed, httputil.Error{ 21 Code: http.StatusMethodNotAllowed, 22 Message: fmt.Sprintf("method %s is not allowed", r.Method), 23 }) 24 }