From 3a60b41bfd1653b246ccf392c3dc45d5238904ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20-=20=E3=82=A2=E3=83=AC=E3=83=83=E3=82=AF=E3=82=B9?= Date: Fri, 29 Nov 2024 14:33:06 +0100 Subject: [PATCH] pass context as argument to Config.Get (#30) --- common.go | 2 +- middleware.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/common.go b/common.go index 8cc6d71..bf1cf50 100644 --- a/common.go +++ b/common.go @@ -61,7 +61,7 @@ type ProjectStore interface { type Config[T any] map[string]map[string]T // Get returns the config value for the given request. -func (c Config[T]) Get(path string) (v T, err error) { +func (c Config[T]) Get(_ context.Context, path string) (v T, err error) { if c == nil { return v, fmt.Errorf("config is nil") } diff --git a/middleware.go b/middleware.go index 3c787da..f666049 100644 --- a/middleware.go +++ b/middleware.go @@ -221,13 +221,14 @@ func AccessControl(acl Config[ACL], cfg Options) func(next http.Handler) http.Ha return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - acl, err := acl.Get(r.URL.Path) + ctx := r.Context() + acl, err := acl.Get(ctx, r.URL.Path) if err != nil { cfg.ErrHandler(r, w, proto.ErrUnauthorized.WithCausef("get acl: %w", err)) return } - if session, _ := GetSessionType(r.Context()); !acl.Includes(session) { + if session, _ := GetSessionType(ctx); !acl.Includes(session) { err := proto.ErrPermissionDenied if session == proto.SessionType_Public { err = proto.ErrUnauthorized