mirror of
https://github.com/outbackdingo/matchbox.git
synced 2026-01-27 18:19:36 +00:00
28 lines
670 B
Go
28 lines
670 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
)
|
|
|
|
// requireGET requires requests to be an HTTP GET. Otherwise, it responds with
|
|
// a 405 status code.
|
|
func requireGET(next http.Handler) http.Handler {
|
|
fn := func(w http.ResponseWriter, req *http.Request) {
|
|
if req.Method != "GET" {
|
|
http.Error(w, "only HTTP GET is supported", http.StatusMethodNotAllowed)
|
|
return
|
|
}
|
|
next.ServeHTTP(w, req)
|
|
}
|
|
return http.HandlerFunc(fn)
|
|
}
|
|
|
|
// logRequests logs HTTP requests.
|
|
func logRequests(next http.Handler) http.Handler {
|
|
fn := func(w http.ResponseWriter, req *http.Request) {
|
|
log.Debugf("HTTP %s %v", req.Method, req.URL)
|
|
next.ServeHTTP(w, req)
|
|
}
|
|
return http.HandlerFunc(fn)
|
|
}
|