More metrics

This commit is contained in:
binwiederhier 2023-03-14 10:19:15 -04:00
parent 754b456320
commit fe731d43cd
8 changed files with 75 additions and 28 deletions

View file

@ -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
}