summaryrefslogtreecommitdiffstats
path: root/utils/utils.go
diff options
context:
space:
mode:
Diffstat (limited to 'utils/utils.go')
-rw-r--r--utils/utils.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/utils/utils.go b/utils/utils.go
index dd60f6060..6d34387c4 100644
--- a/utils/utils.go
+++ b/utils/utils.go
@@ -4,7 +4,11 @@
package utils
import (
+ "net"
+ "net/http"
"os"
+
+ "github.com/mattermost/platform/model"
)
func StringArrayIntersection(arr1, arr2 []string) []string {
@@ -48,3 +52,17 @@ func RemoveDuplicatesFromStringArray(arr []string) []string {
return result
}
+
+func GetIpAddress(r *http.Request) string {
+ address := r.Header.Get(model.HEADER_FORWARDED)
+
+ if len(address) == 0 {
+ address = r.Header.Get(model.HEADER_REAL_IP)
+ }
+
+ if len(address) == 0 {
+ address, _, _ = net.SplitHostPort(r.RemoteAddr)
+ }
+
+ return address
+}