|
@@ -74,7 +74,7 @@ func (r *SQLiteRepo) Migrate() error {
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
fqdn TEXT NOT NULL,
|
|
fqdn TEXT NOT NULL,
|
|
ipv4_address TEXT NOT NULL UNIQUE,
|
|
ipv4_address TEXT NOT NULL UNIQUE,
|
|
- listening_port TEXT NOT NULL
|
|
|
|
|
|
+ listening_port INTEGER[] NOT NULL
|
|
);
|
|
);
|
|
`
|
|
`
|
|
|
|
|
|
@@ -88,7 +88,7 @@ Create an entry in the hosts table
|
|
:param host: a Host entry from a port scan
|
|
:param host: a Host entry from a port scan
|
|
*/
|
|
*/
|
|
func (r *SQLiteRepo) Create(host Host) (*Host, error) {
|
|
func (r *SQLiteRepo) Create(host Host) (*Host, error) {
|
|
- res, err := r.db.Exec("INSERT INTO hosts(fqdn, ipv4_address, listening_port) values(?,?,?)", host.Fqdn, host.IpAddress, host.PortString)
|
|
|
|
|
|
+ res, err := r.db.Exec("INSERT INTO hosts(fqdn, ipv4_address, listening_port) values(?,?,?)", host.Fqdn, host.IpAddress, host.ListeningPorts)
|
|
if err != nil {
|
|
if err != nil {
|
|
var sqliteErr sqlite3.Error
|
|
var sqliteErr sqlite3.Error
|
|
if errors.As(err, &sqliteErr) {
|
|
if errors.As(err, &sqliteErr) {
|
|
@@ -119,7 +119,7 @@ func (r *SQLiteRepo) All() ([]Host, error) {
|
|
var all []Host
|
|
var all []Host
|
|
for rows.Next() {
|
|
for rows.Next() {
|
|
var host Host
|
|
var host Host
|
|
- if err := rows.Scan(&host.Id, &host.Fqdn, &host.IpAddress, &host.PortString); err != nil {
|
|
|
|
|
|
+ if err := rows.Scan(&host.Id, &host.Fqdn, &host.IpAddress, &host.ListeningPorts); err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
all = append(all, host)
|
|
all = append(all, host)
|
|
@@ -132,7 +132,7 @@ func (r *SQLiteRepo) GetByIP(ip string) (*Host, error) {
|
|
row := r.db.QueryRow("SELECT * FROM hosts WHERE ipv4_address = ?", ip)
|
|
row := r.db.QueryRow("SELECT * FROM hosts WHERE ipv4_address = ?", ip)
|
|
|
|
|
|
var host Host
|
|
var host Host
|
|
- if err := row.Scan(&host.Id, &host.Fqdn, &host.IpAddress, &host.PortString); err != nil {
|
|
|
|
|
|
+ if err := row.Scan(&host.Id, &host.Fqdn, &host.IpAddress, &host.ListeningPorts); err != nil {
|
|
if errors.Is(err, sql.ErrNoRows) {
|
|
if errors.Is(err, sql.ErrNoRows) {
|
|
return nil, ErrNotExists
|
|
return nil, ErrNotExists
|
|
}
|
|
}
|
|
@@ -146,7 +146,7 @@ func (r *SQLiteRepo) Update(id int64, updated Host) (*Host, error) {
|
|
if id == 0 {
|
|
if id == 0 {
|
|
return nil, errors.New("invalid updated ID")
|
|
return nil, errors.New("invalid updated ID")
|
|
}
|
|
}
|
|
- res, err := r.db.Exec("UPDATE hosts SET fqdn = ?, ipv4_address = ?, listening_port = ? WHERE id = ?", updated.Fqdn, updated.IpAddress, updated.PortString, id)
|
|
|
|
|
|
+ res, err := r.db.Exec("UPDATE hosts SET fqdn = ?, ipv4_address = ?, listening_port = ? WHERE id = ?", updated.Fqdn, updated.IpAddress, updated.ListeningPorts, id)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|