7eff28053a
Root cause: store List* methods used 'var out []T' which stays nil on empty
result sets and serializes to JSON null; the SPA then crashed on .length/.map
(e.g. endpoints.length on the Tasks page right after deploy). Return []T{}
at the source; coerce null->[] on the frontend load sites as defense-in-depth.
Regression test asserts List* are non-nil when empty.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MMHQTtnQtQqL8muAXHr9kd
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package store
|
|
|
|
import "context"
|
|
|
|
type Endpoint struct {
|
|
ID int64 `json:"id"`
|
|
RoleLabel string `json:"role_label"`
|
|
Host string `json:"host"`
|
|
Port int `json:"port"`
|
|
TLSMode string `json:"tls_mode"`
|
|
}
|
|
|
|
func (s *Store) CreateEndpoint(ctx context.Context, e Endpoint) (int64, error) {
|
|
var id int64
|
|
err := s.Pool.QueryRow(ctx,
|
|
`INSERT INTO endpoints (role_label, host, port, tls_mode)
|
|
VALUES ($1,$2,$3,$4) RETURNING id`,
|
|
e.RoleLabel, e.Host, e.Port, e.TLSMode).Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
func (s *Store) GetEndpoint(ctx context.Context, id int64) (Endpoint, error) {
|
|
var e Endpoint
|
|
err := s.Pool.QueryRow(ctx,
|
|
`SELECT id, role_label, host, port, tls_mode FROM endpoints WHERE id=$1`, id).
|
|
Scan(&e.ID, &e.RoleLabel, &e.Host, &e.Port, &e.TLSMode)
|
|
return e, err
|
|
}
|
|
|
|
func (s *Store) ListEndpoints(ctx context.Context) ([]Endpoint, error) {
|
|
rows, err := s.Pool.Query(ctx,
|
|
`SELECT id, role_label, host, port, tls_mode FROM endpoints ORDER BY id`)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
out := []Endpoint{}
|
|
for rows.Next() {
|
|
var e Endpoint
|
|
if err := rows.Scan(&e.ID, &e.RoleLabel, &e.Host, &e.Port, &e.TLSMode); err != nil {
|
|
return nil, err
|
|
}
|
|
out = append(out, e)
|
|
}
|
|
return out, rows.Err()
|
|
}
|