Polishing

This commit is contained in:
binwiederhier 2023-02-23 20:46:53 -05:00
parent 8eae44ea61
commit 2329695a47
5 changed files with 88 additions and 44 deletions

View file

@ -2,6 +2,7 @@ package server
import (
"context"
"fmt"
"heckel.io/ntfy/util"
"io"
"net/http"
@ -105,3 +106,11 @@ func withContext(r *http.Request, ctx map[contextKey]any) *http.Request {
}
return r.WithContext(c)
}
func fromContext[T any](r *http.Request, key contextKey) *T {
t, ok := r.Context().Value(key).(*T)
if !ok {
panic(fmt.Sprintf("cannot find key %v in request context", key))
}
return t
}