pkgdash/handler/middleware.go
Evstigneev Denis 8886dcba9c add handlers, storage(Postgres, sqlite) (#3)
Reviewed-on: #3
Co-authored-by: Evstigneev Denis <danteevstigneev@yandex.ru>
Co-committed-by: Evstigneev Denis <danteevstigneev@yandex.ru>
2023-08-11 20:12:15 +03:00

22 lines
444 B
Go

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)
}
}