Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c2468a7389 | |||
| b6ba3486d6 | |||
| f59e909d30 |
+11
-7
@@ -357,14 +357,18 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
|
||||
defer func() {
|
||||
//是否展示日志
|
||||
if that.WebConnectLog != nil {
|
||||
ipStr := Substr(context.Req.RemoteAddr, 0, strings.Index(context.Req.RemoteAddr, ":"))
|
||||
|
||||
//负载均衡优化
|
||||
if ipStr == "127.0.0.1" {
|
||||
if req.Header.Get("X-Forwarded-For") != "" {
|
||||
ipStr = req.Header.Get("X-Forwarded-For")
|
||||
} else if req.Header.Get("X-Real-IP") != "" {
|
||||
ipStr = req.Header.Get("X-Real-IP")
|
||||
}
|
||||
ipStr := ""
|
||||
if req.Header.Get("X-Forwarded-For") != "" {
|
||||
ipStr = req.Header.Get("X-Forwarded-For")
|
||||
} else if req.Header.Get("X-Real-IP") != "" {
|
||||
ipStr = req.Header.Get("X-Real-IP")
|
||||
}
|
||||
//负载均衡优化
|
||||
if ipStr == "" {
|
||||
//RemoteAddr := that.Req.RemoteAddr
|
||||
ipStr = Substr(context.Req.RemoteAddr, 0, strings.Index(context.Req.RemoteAddr, ":"))
|
||||
}
|
||||
|
||||
that.WebConnectLog.Infoln(ipStr, context.Req.Method,
|
||||
|
||||
+21
-12
@@ -1069,9 +1069,10 @@ 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 {
|
||||
//是否展示全部子级
|
||||
where := Map{}
|
||||
if req.FormValue("showall") == "1" {
|
||||
|
||||
if req.FormValue("showself") != "" {
|
||||
where := Map{}
|
||||
for _, v := range reqValue {
|
||||
if len(where) == 0 {
|
||||
where[table+"."+parent_idsStr] = "," + v + ","
|
||||
@@ -1079,9 +1080,21 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
}
|
||||
where = Map{"OR": where, table + "." + parent_idsStr: "," + v + ","}
|
||||
}
|
||||
data["OR"] = Map{"OR": where, table + ".id": reqValue}
|
||||
|
||||
} else {
|
||||
data[table+".parent_id"] = reqValue
|
||||
where[table+".parent_id"] = reqValue
|
||||
}
|
||||
//是否展示自己
|
||||
if req.FormValue("showself") == "1" {
|
||||
if len(where) == 0 {
|
||||
data["OR"] = Map{table + ".id": reqValue}
|
||||
} else {
|
||||
data["OR"] = Map{"OR": where, table + ".id": reqValue}
|
||||
}
|
||||
} else {
|
||||
if len(where) != 0 {
|
||||
data["OR"] = where
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1093,14 +1106,9 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
if parent_idsStr != "" {
|
||||
|
||||
where := Map{}
|
||||
if len(reqValue) == 1 {
|
||||
if len(where) == 0 {
|
||||
where[table+"."+searchItem.GetString("name")] = reqValue[0]
|
||||
|
||||
} else {
|
||||
where = Map{"OR": where, table + "." + searchItem.GetString("name"): reqValue[0]}
|
||||
}
|
||||
|
||||
//是否全部展示
|
||||
if req.FormValue("showall") != "1" {
|
||||
where[table+"."+searchItem.GetString("name")] = reqValue
|
||||
} else {
|
||||
for _, v := range reqValue {
|
||||
if len(where) == 0 {
|
||||
@@ -1110,6 +1118,7 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
where = Map{"OR": where, searchItem.GetString("link") + "." + parent_idsStr: "," + v + ","}
|
||||
}
|
||||
}
|
||||
|
||||
//用户
|
||||
if userData[searchItem.GetString("name")] != nil {
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/hex"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
//安全锁
|
||||
@@ -36,6 +37,42 @@ func StrFirstToUpper(str string) string {
|
||||
return strings.ToUpper(first) + other
|
||||
}
|
||||
|
||||
// 时间转字符串,第二个参数支持1-5对应显示年月日时分秒
|
||||
func Time2Str(t *time.Time, qu ...interface{}) string {
|
||||
if t == nil || t.Unix() < 0 {
|
||||
return ""
|
||||
}
|
||||
tp := 5
|
||||
if len(qu) != 0 {
|
||||
tp = (qu[0]).(int)
|
||||
}
|
||||
|
||||
switch tp {
|
||||
case 1:
|
||||
return t.Format("2006-01")
|
||||
case 2:
|
||||
return t.Format("2006-01-02")
|
||||
case 3:
|
||||
return t.Format("2006-01-02 15")
|
||||
case 4:
|
||||
return t.Format("2006-01-02 15:04")
|
||||
case 5:
|
||||
return t.Format("2006-01-02 15:04:05")
|
||||
case 12:
|
||||
return t.Format("01-02")
|
||||
case 14:
|
||||
return t.Format("01-02 15:04")
|
||||
case 15:
|
||||
return t.Format("01-02 15:04:05")
|
||||
case 34:
|
||||
return t.Format("15:04")
|
||||
case 35:
|
||||
return t.Format("15:04:05")
|
||||
}
|
||||
return t.Format("2006-01-02 15:04:05")
|
||||
|
||||
}
|
||||
|
||||
// StrLd 相似度计算 ld compares two strings and returns the levenshtein distance between them.
|
||||
func StrLd(s, t string, ignoreCase bool) int {
|
||||
if ignoreCase {
|
||||
|
||||
+10
-7
@@ -75,14 +75,17 @@ 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")
|
||||
}
|
||||
ipStr := ""
|
||||
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")
|
||||
}
|
||||
//负载均衡优化
|
||||
if ipStr == "" {
|
||||
//RemoteAddr := that.Req.RemoteAddr
|
||||
ipStr = Substr(that.Req.RemoteAddr, 0, strings.Index(that.Req.RemoteAddr, ":"))
|
||||
}
|
||||
that.Log["ip"] = ipStr
|
||||
that.Db.Insert("logs", that.Log)
|
||||
|
||||
@@ -32,7 +32,7 @@ func Down(url, path, name string, e ...*Error) bool {
|
||||
|
||||
pix, err := ioutil.ReadAll(resp.Body)
|
||||
_, err = io.Copy(out, bytes.NewReader(pix))
|
||||
if err != nil && e[0] != nil {
|
||||
if err != nil && len(e) != 0 {
|
||||
e[0].SetError(err)
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user