github.com/blong14/gache@v0.0.0-20240124023949-89416fd8bbfa/internal/server/middleware.go (about) 1 package server 2 3 import ( 4 "net/http" 5 6 ghttp "github.com/blong14/gache/internal/io/http" 7 ) 8 9 func MustBe(method string, next http.HandlerFunc) http.HandlerFunc { 10 return func(w http.ResponseWriter, r *http.Request) { 11 if r.Method != method { 12 err := ErrorResponse{Error: "method not allowed"} 13 ghttp.MustWriteJSON(w, r, http.StatusMethodNotAllowed, err) 14 return 15 } 16 next(w, r) 17 } 18 }