Implement review suggestions

This commit is contained in:
Daniel 2021-01-06 13:34:25 +01:00
parent 5daeac8cf7
commit 3244fefd43
10 changed files with 118 additions and 111 deletions

View file

@ -3,24 +3,20 @@ package api
import "net/http"
// WrapInAuthHandler wraps a simple http.HandlerFunc into a handler that
// exposes the given API permissions.
// exposes the required API permissions for this handler.
func WrapInAuthHandler(fn http.HandlerFunc, read, write Permission) http.Handler {
return &wrappedAuthenticatedHandler{
handleFunc: fn,
read: read,
write: write,
HandlerFunc: fn,
read: read,
write: write,
}
}
type wrappedAuthenticatedHandler struct {
handleFunc http.HandlerFunc
read Permission
write Permission
}
http.HandlerFunc
// ServeHTTP handles the http request.
func (wah *wrappedAuthenticatedHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
wah.handleFunc(w, r)
read Permission
write Permission
}
// ReadPermission returns the read permission for the handler.