Skip to content

Commit

Permalink
feat: added GetAddr func
Browse files Browse the repository at this point in the history
  • Loading branch information
exelban committed Jul 21, 2024
1 parent 0f1c948 commit ee52b7d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,17 @@ func ReadBody(r *http.Request, str interface{}) error {

return nil
}

func GetAddr(r *http.Request) string {
addr := r.RemoteAddr
if CFAddr := r.Header.Get("CF-Connecting-IP"); CFAddr != "" {
addr = CFAddr
}
if addr == "" {
addr = r.Header.Get("X-Forwarded-For")
}
if addr == "" {
addr = r.Header.Get("X-Real-Ip")
}
return addr
}

0 comments on commit ee52b7d

Please sign in to comment.