Skip to content

Commit bf10771

Browse files
author
Ajay Kelkar
committed
feat: location parsing
1 parent 6b1227e commit bf10771

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

session/session.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,15 @@ func (s *Session) SaveSessionDeviceInformation(r *http.Request) {
248248
device.IPAddress = &r.RemoteAddr
249249
}
250250

251-
clientGeoLocation := []string{r.Header.Get("Cf-Ipcity"), r.Header.Get("Cf-Ipcountry")}
251+
var clientGeoLocation []string
252252

253-
var sb strings.Builder
254-
for _, i := range clientGeoLocation {
255-
if sb.Len() != 0 && i != "" {
256-
sb.WriteString(", ")
257-
}
258-
sb.WriteString(i)
253+
if r.Header.Get("Cf-Ipcity") != "" {
254+
clientGeoLocation = append(clientGeoLocation, r.Header.Get("Cf-Ipcity"))
255+
}
256+
if r.Header.Get("Cf-Ipcountry") != "" {
257+
clientGeoLocation = append(clientGeoLocation, r.Header.Get("Cf-Ipcountry"))
259258
}
260-
device.Location = stringsx.GetPointer(sb.String())
259+
device.Location = stringsx.GetPointer(strings.Join(clientGeoLocation, ", "))
261260

262261
s.Devices = append(s.Devices, device)
263262
}

0 commit comments

Comments
 (0)