GetClientString obtains the human readable string of the remote IP and optionally the real client IP if available
(p ipapi.RealClientIPParser, req *http.Request, full bool)
| 92 | |
| 93 | // GetClientString obtains the human readable string of the remote IP and optionally the real client IP if available |
| 94 | func GetClientString(p ipapi.RealClientIPParser, req *http.Request, full bool) (s string) { |
| 95 | var realClientIPStr string |
| 96 | if p != nil { |
| 97 | if realClientIP, err := p.GetRealClientIP(req.Header); err == nil && realClientIP != nil { |
| 98 | realClientIPStr = realClientIP.String() |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | var remoteIPStr string |
| 103 | if remoteIP, err := getRemoteIP(req); err == nil && remoteIP != nil { |
| 104 | remoteIPStr = remoteIP.String() |
| 105 | } |
| 106 | |
| 107 | if !full && realClientIPStr != "" { |
| 108 | return realClientIPStr |
| 109 | } |
| 110 | if full && realClientIPStr != "" { |
| 111 | return fmt.Sprintf("%s (%s)", remoteIPStr, realClientIPStr) |
| 112 | } |
| 113 | return remoteIPStr |
| 114 | } |