Compare commits

..

3 Commits

Author SHA1 Message Date
hoteas f7dfd4ec77 增加记录IP 2022-08-21 03:49:56 +08:00
hoteas 2276aa12ef Merge remote-tracking branch 'origin/master' 2022-08-20 22:38:40 +08:00
hoteas 6505594fd0 增加记录IP 2022-08-20 22:38:15 +08:00
3 changed files with 15 additions and 2 deletions
+1 -1
View File
@@ -376,7 +376,7 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
//访问拦截true继续false暂停
connectListenerLen := len(that.connectListener)
for i := connectListenerLen - 1; i >= 0; i-- {
for i := 0; i < connectListenerLen; i++ {
if that.connectListener[i](&context) {
+3 -1
View File
@@ -1081,7 +1081,9 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
parentID = userData.GetCeilInt(table + "_id")
data["OR"] = Map{table + ".id": parentID, table + ".parent_id": nil}
} else {
data[table+".parent_id"] = reqValue
data["OR"] = Map{table + ".parent_id": reqValue, table + ".id": reqValue}
}
continue
}
+11
View File
@@ -5,6 +5,7 @@ import (
. "code.hoteas.com/golang/hotime/db"
"encoding/json"
"net/http"
"strings"
"time"
)
@@ -74,6 +75,16 @@ func (that *Context) View() {
if that.Session("user_id").Data != nil {
that.Log["user_id"] = that.Session("user_id").ToCeilInt()
}
ipStr := Substr(that.Req.RemoteAddr, 0, strings.Index(that.Req.RemoteAddr, ":"))
//负载均衡优化
if ipStr == "127.0.0.1" {
if that.Req.Header.Get("X-Forwarded-For") != "" {
ipStr = that.Req.Header.Get("X-Forwarded-For")
} else if that.Req.Header.Get("X-Real-IP") != "" {
ipStr = that.Req.Header.Get("X-Real-IP")
}
}
that.Log["ip"] = ipStr
that.Db.Insert("logs", that.Log)
}