test ip
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"github.com/astaxie/beego/client/orm"
|
"github.com/astaxie/beego/client/orm"
|
||||||
"github.com/astaxie/beego/server/web"
|
"github.com/astaxie/beego/server/web"
|
||||||
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -249,7 +250,7 @@ func (c *ApiController) UpdatePrinter(dataMap map[string]interface{}) (data, err
|
|||||||
printNo, name, sim, sound string
|
printNo, name, sim, sound string
|
||||||
appID, volume int
|
appID, volume int
|
||||||
)
|
)
|
||||||
globals.SugarLogger.Debugf("Begin API UpdatePrinter data: [%v]", utils.Format4Output(dataMap, false))
|
globals.SugarLogger.Debugf("Begin API UpdatePrinter data: [%v], ip: %v", utils.Format4Output(dataMap, false), getRealRemoteIP(c.Ctx.Request))
|
||||||
if _, ok := dataMap[keyPrintNo].(string); !ok {
|
if _, ok := dataMap[keyPrintNo].(string); !ok {
|
||||||
return buildParamErrCodeAndErr(keyPrintNo)
|
return buildParamErrCodeAndErr(keyPrintNo)
|
||||||
} else {
|
} else {
|
||||||
@@ -377,3 +378,18 @@ func (c *ApiController) GetPrinterStatus(dataMap map[string]interface{}) (data,
|
|||||||
}
|
}
|
||||||
return data, errCode, err
|
return data, errCode, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getRealRemoteIP(r *http.Request) (ip string) {
|
||||||
|
if r != nil {
|
||||||
|
ip = r.Header.Get("X-Forwarded-For")
|
||||||
|
if ip == "" {
|
||||||
|
ip = r.Header.Get("X-real-ip")
|
||||||
|
}
|
||||||
|
if ip == "" {
|
||||||
|
ip = strings.Split(r.RemoteAddr, ":")[0]
|
||||||
|
} else {
|
||||||
|
ip = strings.Split(ip, ",")[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ip
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user