mirror of
https://git.sr.ht/~sircmpwn/tokidoki
synced 2025-12-12 06:07:22 +01:00
Keep context keys private
Instead, offer type safe accessors, as documented here: https://pkg.go.dev/context#Context
This commit is contained in:
parent
07c19a6f6c
commit
78bd2a9b84
3 changed files with 18 additions and 11 deletions
|
|
@ -37,14 +37,14 @@ func NewFilesystem(path string) (carddav.Backend, error) {
|
|||
}
|
||||
|
||||
func (b *filesystemBackend) pathForContext(ctx context.Context) (string, error) {
|
||||
raw := ctx.Value(auth.AuthCtxKey)
|
||||
if raw == nil {
|
||||
return "", fmt.Errorf("unauthenticated requests are not supported")
|
||||
}
|
||||
authCtx, ok := raw.(*auth.AuthContext)
|
||||
authCtx, ok := auth.FromContext(ctx)
|
||||
if !ok {
|
||||
panic("Invalid data in auth context!")
|
||||
}
|
||||
if authCtx == nil {
|
||||
return "", fmt.Errorf("unauthenticated requests are not supported")
|
||||
}
|
||||
|
||||
userDir := base64.RawStdEncoding.EncodeToString([]byte(authCtx.UserName))
|
||||
path := filepath.Join(b.path, userDir)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue