check / check (push) Waiting to run
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> and lists the matches
as links to their AS pages. asinfo.Search ignores case, returns the first
matches up to a limit in AS number order, and counts all matches. An
empty q answers 400.
When the database has no record of an AS, its page and /api/v1/as/{asn}
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. AS 0 means no known origin: it always answers 404, and the search
never lists it.
Model: opus-5-5
37 lines
741 B
Go
37 lines
741 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() {
|
|
const limit = 10
|
|
|
|
results, total := asinfo.Search("mit-gateway", limit)
|
|
|
|
fmt.Printf("%d of %d matches\n", len(results), total)
|
|
|
|
for _, info := range results {
|
|
fmt.Printf("AS%d: %s - %s\n", info.ASN, info.Handle, info.Description)
|
|
}
|
|
// Output:
|
|
// 1 of 1 matches
|
|
// AS3: MIT-GATEWAYS - Massachusetts Institute of Technology
|
|
}
|