From 9df12177ebe2e710eea4d322c57ff5c928e84059 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Tue, 19 Mar 2024 14:29:09 +0100 Subject: [PATCH] Minor idiomatic pass on internal/http/request/context.go --- internal/http/request/context.go | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/internal/http/request/context.go b/internal/http/request/context.go index b2ce54cf..ba6ee40d 100644 --- a/internal/http/request/context.go +++ b/internal/http/request/context.go @@ -37,14 +37,10 @@ const ( func WebAuthnSessionData(r *http.Request) *model.WebAuthnSession { if v := r.Context().Value(WebAuthnDataContextKey); v != nil { - value, valid := v.(model.WebAuthnSession) - if !valid { - return nil + if value, valid := v.(model.WebAuthnSession); valid { + return &value } - - return &value } - return nil } @@ -151,39 +147,27 @@ func ClientIP(r *http.Request) string { func getContextStringValue(r *http.Request, key ContextKey) string { if v := r.Context().Value(key); v != nil { - value, valid := v.(string) - if !valid { - return "" + if value, valid := v.(string); valid { + return value } - - return value } - return "" } func getContextBoolValue(r *http.Request, key ContextKey) bool { if v := r.Context().Value(key); v != nil { - value, valid := v.(bool) - if !valid { - return false + if value, valid := v.(bool); valid { + return value } - - return value } - return false } func getContextInt64Value(r *http.Request, key ContextKey) int64 { if v := r.Context().Value(key); v != nil { - value, valid := v.(int64) - if !valid { - return 0 + if value, valid := v.(int64); valid { + return value } - - return value } - return 0 }