first commit
This commit is contained in:
23
internal/data/query.go
Normal file
23
internal/data/query.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
)
|
||||
|
||||
func (d *IpDb) Query(ipArg string) (map[string]any, *net.IPNet, error) {
|
||||
ip := net.ParseIP(ipArg)
|
||||
if ip == nil {
|
||||
return nil, nil, fmt.Errorf("invalid IP: %s", ipArg)
|
||||
}
|
||||
// Get data of IP.
|
||||
anyData := make(map[string]any)
|
||||
recordNet, ok, err := d.r.LookupNetwork(ip, &anyData)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if !ok {
|
||||
return nil, nil, fmt.Errorf("IP not found: %s", ipArg)
|
||||
}
|
||||
return anyData, recordNet, nil
|
||||
}
|
||||
Reference in New Issue
Block a user