24 lines
473 B
Go
24 lines
473 B
Go
|
package utility
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"strings"
|
||
|
|
||
|
"code.nonshy.com/nonshy/website/pkg/config"
|
||
|
)
|
||
|
|
||
|
/*
|
||
|
IPAddress returns the best guess at the user's IP address, as a string for logging.
|
||
|
*/
|
||
|
func IPAddress(r *http.Request) string {
|
||
|
if config.Current.UseXForwardedFor {
|
||
|
if realIP := r.Header.Get("X-Real-IP"); realIP != "" {
|
||
|
return realIP
|
||
|
}
|
||
|
if xff := r.Header.Get("X-Forwarded-For"); xff != "" {
|
||
|
return strings.SplitN(xff, " ", 1)[0]
|
||
|
}
|
||
|
}
|
||
|
return r.RemoteAddr
|
||
|
}
|