Skip to content

Commit 3a60b41

Browse files
authored
pass context as argument to Config.Get (#30)
1 parent 724a470 commit 3a60b41

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type ProjectStore interface {
6161
type Config[T any] map[string]map[string]T
6262

6363
// Get returns the config value for the given request.
64-
func (c Config[T]) Get(path string) (v T, err error) {
64+
func (c Config[T]) Get(_ context.Context, path string) (v T, err error) {
6565
if c == nil {
6666
return v, fmt.Errorf("config is nil")
6767
}

middleware.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,14 @@ func AccessControl(acl Config[ACL], cfg Options) func(next http.Handler) http.Ha
221221

222222
return func(next http.Handler) http.Handler {
223223
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
224-
acl, err := acl.Get(r.URL.Path)
224+
ctx := r.Context()
225+
acl, err := acl.Get(ctx, r.URL.Path)
225226
if err != nil {
226227
cfg.ErrHandler(r, w, proto.ErrUnauthorized.WithCausef("get acl: %w", err))
227228
return
228229
}
229230

230-
if session, _ := GetSessionType(r.Context()); !acl.Includes(session) {
231+
if session, _ := GetSessionType(ctx); !acl.Includes(session) {
231232
err := proto.ErrPermissionDenied
232233
if session == proto.SessionType_Public {
233234
err = proto.ErrUnauthorized

0 commit comments

Comments
 (0)