Explorar o código

Minor idiomatic pass on internal/http/request/context.go

jvoisin %!s(int64=2) %!d(string=hai) anos
pai
achega
9df12177eb
Modificáronse 1 ficheiros con 8 adicións e 24 borrados
  1. 8 24
      internal/http/request/context.go

+ 8 - 24
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
 }