From a4824ab93d3b8920752196c20b93015d86e1511e Mon Sep 17 00:00:00 2001 From: JesusPerez Date: Thu, 24 Mar 2022 12:57:54 +0000 Subject: [PATCH] chore: add requestInfo and IP to TrackAction --- logs.go | 13 +++++++++++++ types.go | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/logs.go b/logs.go index ef3fe51..631474f 100644 --- a/logs.go +++ b/logs.go @@ -121,4 +121,17 @@ func logRequest(c *gin.Context, rtenv *RouteEnv, run string, route string, info "tkn": tkn, }).Info(infoReq) } +} +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) + return LogInfo{ + Run: run, + Route: route, + Lang: fmt.Sprintf("%+v",langs), + Agent: fmt.Sprintf("%+v",c.Request.UserAgent()), + Ip: ip, + Tkn: tkn, + } } \ No newline at end of file diff --git a/types.go b/types.go index 6488834..9061fd1 100644 --- a/types.go +++ b/types.go @@ -82,6 +82,14 @@ type ConfigPostData struct { Val string `yaml:"val" json:"val"` Config cfg.Config `yaml:"config" json:"config"` } +type LogInfo struct { + Run string `yaml:"run" json:"run"` + Route string `yaml:"route" json:"route"` + Lang string `yaml:"lang" json:"lang"` + Agent string `yaml:"agent" json:"agent"` + Ip string `yaml:"ip" json:"ip"` + Tkn string `yaml:"tkn" json:"tkn"` +} type TrackAction struct { When string `yaml:"when" json:"when"` Where string `yaml:"where" json:"where"` @@ -89,6 +97,7 @@ type TrackAction struct { Context string `yaml:"context" json:"context"` Data string `yaml:"data" json:"data"` Auth string `yaml:"auth" json:"auth"` + Ip string `yaml:"ip" json:"ip"` } type PostTrackAction struct { When string `yaml:"when" json:"when"`