Make the home page's AS name search work (closes #151)
check / check (push) Canceled after 0s

The AS Name Search card on the home page said the search was coming
soon. It now asks the new GET /api/v1/search/as?q=<text>, which
searches the AS list built into asinfo, and lists the matches as links
to their AS pages. An empty q answers 400. asinfo.Search now ignores
case and returns its matches in AS number order.

A match can be an AS that the database does not hold yet. Its AS page
and /api/v1/as/{asn} now answer with its handle and description from
asinfo and no prefixes, instead of 404. Empty prefix lists in that JSON
answer are [] rather than null.

Model: opus-5-5
This commit is contained in:
2026-10-26 20:39:30 +00:00
parent 71ee2aeda7
commit ca68b8f605
15 changed files with 622 additions and 67 deletions
+12 -1
View File
@@ -1748,6 +1748,10 @@ func (d *Database) GetASDetails(asn int) (*ASN, []LiveRoute, error) {
// GetASDetailsContext returns the AS and the prefixes it originates, the IPv4
// ones first, each once with the time of its newest route. It makes two index
// searches per prefix, however many peers carry the prefix.
//
// An AS that only the AS info lookup knows comes with its handle and
// description, and without prefixes or seen times. An AS that neither the
// database nor the lookup knows is ErrNoRoute.
func (d *Database) GetASDetailsContext(
ctx context.Context, asn int,
) (*ASN, []LiveRoute, error) {
@@ -1765,7 +1769,14 @@ func (d *Database) GetASDetailsContext(
&asnInfo.LastSeen)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, nil, fmt.Errorf("%w: AS%d", ErrNoRoute, asn)
info, ok := asinfo.Get(asn)
if !ok {
return nil, nil, fmt.Errorf("%w: AS%d", ErrNoRoute, asn)
}
return &ASN{
ASN: asn, Handle: info.Handle, Description: info.Description,
}, nil, nil
}
return nil, nil, fmt.Errorf("failed to query AS: %w", err)