package handler import "net/http" func Methods(m string, next http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { if req.Method != m { http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) return } switch req.Method { case http.MethodPost: w.WriteHeader(http.StatusCreated) case http.MethodPut: w.WriteHeader(http.StatusNoContent) } next.ServeHTTP(w, req) } }