diff options
Diffstat (limited to 'utils')
-rw-r--r-- | utils/config.go | 10 | ||||
-rw-r--r-- | utils/utils.go | 18 |
2 files changed, 28 insertions, 0 deletions
diff --git a/utils/config.go b/utils/config.go index ab149d55f..da070012e 100644 --- a/utils/config.go +++ b/utils/config.go @@ -32,6 +32,15 @@ var CfgHash = "" var CfgFileName string = "" var ClientCfg map[string]string = map[string]string{} var originalDisableDebugLvl l4g.Level = l4g.DEBUG +var siteURL = "" + +func GetSiteURL() string { + return siteURL +} + +func SetSiteURL(url string) { + siteURL = url +} func FindConfigFile(fileName string) string { if _, err := os.Stat("./config/" + fileName); err == nil { @@ -215,6 +224,7 @@ func LoadConfig(fileName string) { } SetDefaultRolesBasedOnConfig() + SetSiteURL(*Cfg.ServiceSettings.SiteURL) } func RegenerateClientConfig() { 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 +} |