Files
routewatch/pkg/asinfo/example_test.go
T
sneak e9308df2a3
check / check (push) Canceled after 0s
Make the home page's AS name search work (closes #151)
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. asinfo puts each
handle and description in lower case once, when the list loads.

A match can be an AS that the database has no record of. Its AS page
and /api/v1/as/{asn} then take its handle and description from asinfo
and still list its prefixes. They answer 404 only for an AS with no
record, no asinfo entry and no prefix. Empty prefix lists in that JSON
answer are [] rather than null.

Model: opus-5-5
2026-10-26 20:59:03 +00:00

30 lines
628 B
Go

package asinfo_test
import (
"fmt"
"git.eeqj.de/sneak/routewatch/pkg/asinfo"
)
func ExampleGet() {
info, ok := asinfo.Get(15169)
if ok {
fmt.Printf("AS%d: %s - %s\n", info.ASN, info.Handle, info.Description)
}
// Output: AS15169: GOOGLE - Google LLC
}
func ExampleGetDescription() {
desc := asinfo.GetDescription(13335)
fmt.Println(desc)
// Output: Cloudflare, Inc.
}
func ExampleSearch() {
results := asinfo.Search("mit-gateway")
for _, info := range results {
fmt.Printf("AS%d: %s - %s\n", info.ASN, info.Handle, info.Description)
}
// Output: AS3: MIT-GATEWAYS - Massachusetts Institute of Technology
}