Skip to content

Commit d3c9ec6

Browse files
author
Ajay Kelkar
committed
fix: support null values
1 parent b866ca3 commit d3c9ec6

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

session/session.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ type Session struct {
8282
Identity *identity.Identity `json:"identity" faker:"identity" db:"-" belongs_to:"identities" fk_id:"IdentityID"`
8383

8484
// IP address of the machine where the session was initiated
85-
ClientIPAddress string `json:"client_ip_address" db:"client_ip_address"`
85+
ClientIPAddress *string `json:"client_ip_address" db:"client_ip_address"`
8686

8787
// User Agent
88-
UserAgent string `json:"user_agent" db:"user_agent"`
88+
UserAgent *string `json:"user_agent" db:"user_agent"`
8989

9090
// Geo Location where the session was initiated
91-
GeoLocation string `json:"geo_location" db:"geo_location"`
91+
GeoLocation *string `json:"geo_location" db:"geo_location"`
9292

9393
// IdentityID is a helper struct field for gobuffalo.pop.
9494
IdentityID uuid.UUID `json:"-" faker:"-" db:"identity_id"`
@@ -196,14 +196,14 @@ func (s *Session) Activate(r *http.Request, i *identity.Identity, c lifespanProv
196196
}
197197

198198
if trueClientIP := r.Header.Get("True-Client-IP"); trueClientIP != "" {
199-
s.ClientIPAddress = trueClientIP
199+
s.ClientIPAddress = &trueClientIP
200200
} else if realClientIP := r.Header.Get("X-Real-IP"); realClientIP != "" {
201-
s.ClientIPAddress = realClientIP
201+
s.ClientIPAddress = &realClientIP
202202
} else if forwardedIP := r.Header.Get("X-Forwarded-For"); forwardedIP != "" {
203203
// TODO: Use x lib implementation to parse client IP address from the header string
204-
s.ClientIPAddress = forwardedIP
204+
s.ClientIPAddress = &forwardedIP
205205
} else {
206-
s.ClientIPAddress = r.RemoteAddr
206+
s.ClientIPAddress = &r.RemoteAddr
207207
}
208208

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

0 commit comments

Comments
 (0)