main
1package authz
2
3import "net/http"
4
5type Authorizer interface {
6 Authorize(*http.Request) bool
7}
8
9type AuthorizerFunc func(*http.Request) bool
10
11func (f AuthorizerFunc) Authorize(r *http.Request) bool {
12 return f(r)
13}
14
15func HTTP(authorizer Authorizer, h http.Handler) http.Handler {
16 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
17 if authorizer.Authorize(r) {
18 h.ServeHTTP(w, r)
19 } else {
20 w.WriteHeader(http.StatusForbidden)
21 }
22 })
23}