mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-04-06 22:47:38 +03:00
More metrics
This commit is contained in:
parent
754b456320
commit
fe731d43cd
8 changed files with 75 additions and 28 deletions
|
@ -107,10 +107,10 @@ 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 {
|
||||
func fromContext[T any](r *http.Request, key contextKey) (T, error) {
|
||||
t, ok := r.Context().Value(key).(T)
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("cannot find key %v in request context", key))
|
||||
return t, fmt.Errorf("cannot find key %v in request context", key)
|
||||
}
|
||||
return t
|
||||
return t, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue