From 97558f6a6ec4c53fa69035fb430ead209d9c222d Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Fri, 13 Jan 2017 13:53:37 -0500 Subject: PLT-4938 Add app package and move logic over from api package (#4931) * Add app package and move logic over from api package * Change app package functions to return errors * Move non-api tests into app package * Fix merge --- utils/utils.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'utils/utils.go') 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 +} -- cgit v1.2.3-1-g7c22