chore: trace show tracking ip

This commit is contained in:
JesusPerez 2022-03-24 13:47:29 +00:00
parent a4824ab93d
commit f0e8f8fa94
2 changed files with 11 additions and 4 deletions

View File

@ -109,7 +109,7 @@ func post_tracking_handle(c *gin.Context, rtenv *RouteEnv) {
}
}
}
ip, _ := getIP(c.Request)
ip, _ := getIP(c.Request,true)
trackaction := &TrackAction{
When: trackpost.When,
Where: trackpost.Where,

13
logs.go
View File

@ -57,9 +57,16 @@ func setLog(cfg *cfg.Config) {
})
}
func getIP(r *http.Request) (string, error) {
func getIP(r *http.Request,show bool) (string, error) {
//Get IP from X-FORWARDED-FOR header
ips := r.Header.Get("X-FORWARDED-FOR")
if show {
fmt.Println("X-Forwarded-For : ", ips)
ipreal := r.Header.Get("X-REAL-IP")
fmt.Println("X-REAL-IP : ", ipreal)
iprem, _, _ := net.SplitHostPort(r.RemoteAddr)
fmt.Println("RemoteAddr : ", iprem)
}
splitIps := strings.Split(ips, ",")
for _, ip := range splitIps {
netIP := net.ParseIP(ip)
@ -88,7 +95,7 @@ func getIP(r *http.Request) (string, error) {
func logRequest(c *gin.Context, rtenv *RouteEnv, run string, route string, info string, infoReq string, tkn string) {
accept_langs := strings.Split(c.Request.Header.Get("Accept-Language"),";")
langs := strings.Split(accept_langs[0], ",")
ip, _ := getIP(c.Request)
ip, _ := getIP(c.Request,false)
// header, _ := ioutil.ReadAll(c.Request.Header)
//println(string(c.header))
// println(c.Header)
@ -125,7 +132,7 @@ func logRequest(c *gin.Context, rtenv *RouteEnv, run string, route string, info
func requestInfo(c *gin.Context, rtenv *RouteEnv, run string, route string, tkn string) LogInfo {
accept_langs := strings.Split(c.Request.Header.Get("Accept-Language"),";")
langs := strings.Split(accept_langs[0], ",")
ip, _ := getIP(c.Request)
ip, _ := getIP(c.Request,false)
return LogInfo{
Run: run,
Route: route,