Add /api/v1/ip/<ip> endpoint for IP to AS lookups

- Add handleIPLookup handler that uses GetASInfoForIP
- Create writeJSONError and writeJSONSuccess helper functions
- Refactor all JSON error responses to use the helpers
- Add GetASInfoForIP to Store interface
- Add mock implementation for tests
- Fix all linter warnings
This commit is contained in:
2025-07-28 03:31:53 +02:00
parent afb916036c
commit 691710bc7c
3 changed files with 67 additions and 30 deletions

View File

@@ -187,6 +187,17 @@ func (m *mockStore) GetLiveRouteCounts() (ipv4Count, ipv6Count int, err error) {
return m.RouteCount / 2, m.RouteCount / 2, nil
}
// GetASInfoForIP mock implementation
func (m *mockStore) GetASInfoForIP(ip string) (*database.ASInfo, error) {
// Simple mock - return a test AS
return &database.ASInfo{
ASN: 15169,
Handle: "GOOGLE",
Description: "Google LLC",
Prefix: "8.8.8.0/24",
}, nil
}
func TestRouteWatchLiveFeed(t *testing.T) {
// Create mock database