mirror of https://github.com/miniflux/v2.git
Minor idiomatic pass on internal/http/request/context.go
This commit is contained in:
parent
a78d1c79da
commit
9df12177eb
|
@ -37,14 +37,10 @@ const (
|
||||||
|
|
||||||
func WebAuthnSessionData(r *http.Request) *model.WebAuthnSession {
|
func WebAuthnSessionData(r *http.Request) *model.WebAuthnSession {
|
||||||
if v := r.Context().Value(WebAuthnDataContextKey); v != nil {
|
if v := r.Context().Value(WebAuthnDataContextKey); v != nil {
|
||||||
value, valid := v.(model.WebAuthnSession)
|
if value, valid := v.(model.WebAuthnSession); valid {
|
||||||
if !valid {
|
return &value
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,39 +147,27 @@ func ClientIP(r *http.Request) string {
|
||||||
|
|
||||||
func getContextStringValue(r *http.Request, key ContextKey) string {
|
func getContextStringValue(r *http.Request, key ContextKey) string {
|
||||||
if v := r.Context().Value(key); v != nil {
|
if v := r.Context().Value(key); v != nil {
|
||||||
value, valid := v.(string)
|
if value, valid := v.(string); valid {
|
||||||
if !valid {
|
return value
|
||||||
return ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func getContextBoolValue(r *http.Request, key ContextKey) bool {
|
func getContextBoolValue(r *http.Request, key ContextKey) bool {
|
||||||
if v := r.Context().Value(key); v != nil {
|
if v := r.Context().Value(key); v != nil {
|
||||||
value, valid := v.(bool)
|
if value, valid := v.(bool); valid {
|
||||||
if !valid {
|
return value
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func getContextInt64Value(r *http.Request, key ContextKey) int64 {
|
func getContextInt64Value(r *http.Request, key ContextKey) int64 {
|
||||||
if v := r.Context().Value(key); v != nil {
|
if v := r.Context().Value(key); v != nil {
|
||||||
value, valid := v.(int64)
|
if value, valid := v.(int64); valid {
|
||||||
if !valid {
|
return value
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue