github.com/safing/portbase@v0.19.5/api/auth_wrapper.go (about) 1 package api 2 3 import "net/http" 4 5 // WrapInAuthHandler wraps a simple http.HandlerFunc into a handler that 6 // exposes the required API permissions for this handler. 7 func WrapInAuthHandler(fn http.HandlerFunc, read, write Permission) http.Handler { 8 return &wrappedAuthenticatedHandler{ 9 HandlerFunc: fn, 10 read: read, 11 write: write, 12 } 13 } 14 15 type wrappedAuthenticatedHandler struct { 16 http.HandlerFunc 17 18 read Permission 19 write Permission 20 } 21 22 // ReadPermission returns the read permission for the handler. 23 func (wah *wrappedAuthenticatedHandler) ReadPermission(r *http.Request) Permission { 24 return wah.read 25 } 26 27 // WritePermission returns the write permission for the handler. 28 func (wah *wrappedAuthenticatedHandler) WritePermission(r *http.Request) Permission { 29 return wah.write 30 }