2021-11-10 19:06:12 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net"
|
|
|
|
|
|
|
|
"github.com/dcarrillo/whatismyip/models"
|
|
|
|
)
|
|
|
|
|
2021-11-30 16:21:01 +00:00
|
|
|
// Geo defines a base type for lookups
|
2021-11-10 19:06:12 +00:00
|
|
|
type Geo struct {
|
|
|
|
IP net.IP
|
|
|
|
}
|
|
|
|
|
2021-11-30 16:21:01 +00:00
|
|
|
// LookUpCity queries the database for city data related to the given IP
|
2021-11-10 19:06:12 +00:00
|
|
|
func (g *Geo) LookUpCity() *models.GeoRecord {
|
|
|
|
record := &models.GeoRecord{}
|
|
|
|
err := record.LookUp(g.IP)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return record
|
|
|
|
}
|
|
|
|
|
2021-11-30 16:21:01 +00:00
|
|
|
// LookUpASN queries the database for ASN data related to the given IP
|
2021-11-10 19:06:12 +00:00
|
|
|
func (g *Geo) LookUpASN() *models.ASNRecord {
|
|
|
|
record := &models.ASNRecord{}
|
|
|
|
err := record.LookUp(g.IP)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return record
|
|
|
|
}
|