summaryrefslogtreecommitdiff
path: root/utilities.go
diff options
context:
space:
mode:
Diffstat (limited to 'utilities.go')
-rw-r--r--utilities.go18
1 files changed, 17 insertions, 1 deletions
diff --git a/utilities.go b/utilities.go
index 4bf0b92..3ce3e1d 100644
--- a/utilities.go
+++ b/utilities.go
@@ -5,6 +5,7 @@ import (
"fmt"
"io"
"log"
+ "net"
"net/http"
"strings"
)
@@ -33,7 +34,7 @@ func CompareStrings(strs ...string) bool {
func GetLanguage(r *http.Request) string {
c, err := r.Cookie("lang")
if err != nil {
- log.Println("Cookie: lang", err)
+ log.Println("Info: Cookie: lang", err)
} else {
if c.Value != "" {
if c.Value == "de" {
@@ -53,3 +54,18 @@ func GetLanguage(r *http.Request) string {
}
return ""
}
+
+func GetIP(r *http.Request) string {
+ if len(r.Header["X-Forwarded-For"]) > 0 {
+ return r.Header["X-Forwarded-For"][0]
+ }
+ if len(r.Header["X-Real-Ip"]) > 0 {
+ return r.Header["X-Real-Ip"][0]
+ }
+ if r.RemoteAddr != "" {
+ ip, _, _ := net.SplitHostPort(r.RemoteAddr)
+ return ip
+ }
+ log.Println("Info: No remote IP detectable.")
+ return "0.0.0.0"
+}