mirror of
https://github.com/miniflux/v2.git
synced 2025-09-15 18:57:04 +00:00
Store client IP address in request context
This commit is contained in:
parent
c1e1506720
commit
c9f9dd3262
9 changed files with 46 additions and 19 deletions
|
@ -24,6 +24,7 @@ const (
|
|||
FlashMessageContextKey
|
||||
FlashErrorMessageContextKey
|
||||
PocketRequestTokenContextKey
|
||||
ClientIPContextKey
|
||||
)
|
||||
|
||||
// IsAdminUser checks if the logged user is administrator.
|
||||
|
@ -103,6 +104,11 @@ func PocketRequestToken(r *http.Request) string {
|
|||
return getContextStringValue(r, PocketRequestTokenContextKey)
|
||||
}
|
||||
|
||||
// ClientIP returns the client IP address stored in the context.
|
||||
func ClientIP(r *http.Request) string {
|
||||
return getContextStringValue(r, ClientIPContextKey)
|
||||
}
|
||||
|
||||
func getContextStringValue(r *http.Request, key ContextKey) string {
|
||||
if v := r.Context().Value(key); v != nil {
|
||||
return v.(string)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue