Fix unmarshalling of ip from postgres

This commit is contained in:
Torjus Håkestad 2021-04-14 18:01:11 +02:00
parent 82d07eaaf4
commit c1a1bf0b03

View File

@ -3,6 +3,7 @@ package store
import (
"database/sql"
"fmt"
"net"
_ "github.com/jackc/pgx/v4/stdlib"
"github.uio.no/torjus/apiary/models"
@ -188,9 +189,11 @@ func (s *PostgresStore) Query(query AttemptQuery) ([]models.LoginAttempt, error)
var results []models.LoginAttempt
for rows.Next() {
var la models.LoginAttempt
if err := rows.Scan(&la.ID, &la.Date, &la.RemoteIP, &la.Username, &la.Password, &la.SSHClientVersion, &la.ConnectionUUID, &la.Country); err != nil {
var ipString string
if err := rows.Scan(&la.ID, &la.Date, &ipString, &la.Username, &la.Password, &la.SSHClientVersion, &la.ConnectionUUID, &la.Country); err != nil {
return nil, fmt.Errorf("Unable to unmarshal data from database: %w", err)
}
la.RemoteIP = net.ParseIP(ipString)
results = append(results, la)
}