Get real IP for verification log.

This commit is contained in:
Yang Luo
2021-08-03 22:18:59 +08:00
parent acca9eacdc
commit 0c657f0487
4 changed files with 6 additions and 7 deletions

View File

@ -44,7 +44,7 @@ func GetIPInfo(clientIP string) string {
return res
}
func getIPFromRequest(req *http.Request) string {
func GetIPFromRequest(req *http.Request) string {
clientIP := req.Header.Get("x-forwarded-for")
if clientIP == "" {
ipPort := strings.Split(req.RemoteAddr, ":")
@ -62,11 +62,11 @@ func getIPFromRequest(req *http.Request) string {
}
func LogInfo(ctx *context.Context, f string, v ...interface{}) {
ipString := fmt.Sprintf("(%s) ", getIPFromRequest(ctx.Request))
ipString := fmt.Sprintf("(%s) ", GetIPFromRequest(ctx.Request))
logs.Info(ipString+f, v...)
}
func LogWarning(ctx *context.Context, f string, v ...interface{}) {
ipString := fmt.Sprintf("(%s) ", getIPFromRequest(ctx.Request))
ipString := fmt.Sprintf("(%s) ", GetIPFromRequest(ctx.Request))
logs.Warning(ipString+f, v...)
}

View File

@ -30,7 +30,7 @@ type Record struct {
}
func Records(ctx *context.Context) *Record {
ip := strings.Replace(getIPFromRequest(ctx.Request), ": ", "", -1)
ip := strings.Replace(GetIPFromRequest(ctx.Request), ": ", "", -1)
currenttime := GetCurrentTime()
requesturi := ctx.Request.RequestURI
action := strings.Replace(ctx.Request.URL.Path, "/api/", "", -1)