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