mirror of https://github.com/mpolden/echoip
Fix indention
This commit is contained in:
parent
f77fb4fbc0
commit
b6acdacddd
|
@ -16,7 +16,7 @@ func main() {
|
|||
var opts struct {
|
||||
CountryDBPath string `short:"f" long:"country-db" description:"Path to GeoIP country database" value-name:"FILE" default:""`
|
||||
CityDBPath string `short:"c" long:"city-db" description:"Path to GeoIP city database" value-name:"FILE" default:""`
|
||||
ASNDBPath string `short:"a" long:"asn-db" description:"Path to GeoIP ASN database" value-name:"FILE" default:""`
|
||||
ASNDBPath string `short:"a" long:"asn-db" description:"Path to GeoIP ASN database" value-name:"FILE" default:""`
|
||||
Listen string `short:"l" long:"listen" description:"Listening address" value-name:"ADDR" default:":8080"`
|
||||
ReverseLookup bool `short:"r" long:"reverse-lookup" description:"Perform reverse hostname lookups"`
|
||||
PortLookup bool `short:"p" long:"port-lookup" description:"Enable port lookup"`
|
||||
|
|
47
http/http.go
47
http/http.go
|
@ -29,16 +29,16 @@ type Server struct {
|
|||
}
|
||||
|
||||
type Response struct {
|
||||
IP net.IP `json:"ip"`
|
||||
IPDecimal uint64 `json:"ip_decimal"`
|
||||
Country string `json:"country,omitempty"`
|
||||
CountryISO string `json:"country_iso,omitempty"`
|
||||
IsInEuropeanUnion bool `json:"is_in_european_union,omitempty"`
|
||||
City string `json:"city,omitempty"`
|
||||
Hostname string `json:"hostname,omitempty"`
|
||||
LocationLatitude float64 `json:"location_latitude,omitempty"`
|
||||
LocationLongitude float64 `json:"location_longitude,omitempty"`
|
||||
AutonomousSystemNumber string `json:"asn_number,omitempty"`
|
||||
IP net.IP `json:"ip"`
|
||||
IPDecimal uint64 `json:"ip_decimal"`
|
||||
Country string `json:"country,omitempty"`
|
||||
CountryISO string `json:"country_iso,omitempty"`
|
||||
IsInEuropeanUnion bool `json:"is_in_european_union,omitempty"`
|
||||
City string `json:"city,omitempty"`
|
||||
Hostname string `json:"hostname,omitempty"`
|
||||
LocationLatitude float64 `json:"location_latitude,omitempty"`
|
||||
LocationLongitude float64 `json:"location_longitude,omitempty"`
|
||||
AutonomousSystemNumber string `json:"asn_number,omitempty"`
|
||||
AutonomousSystemOrganization string `json:"asn_organization,omitempty"`
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,6 @@ func ipFromRequest(header string, r *http.Request) (net.IP, error) {
|
|||
if ip != nil {
|
||||
remoteIP = ip.String()
|
||||
}
|
||||
fmt.Printf("IP: %v\n", ip)
|
||||
}
|
||||
if remoteIP == "" {
|
||||
host, _, err := net.SplitHostPort(r.RemoteAddr)
|
||||
|
@ -68,7 +67,6 @@ func ipFromRequest(header string, r *http.Request) (net.IP, error) {
|
|||
}
|
||||
remoteIP = host
|
||||
}
|
||||
fmt.Printf("Remote: %v\n", remoteIP)
|
||||
ip := net.ParseIP(remoteIP)
|
||||
if ip == nil {
|
||||
return nil, fmt.Errorf("could not parse IP: %s", remoteIP)
|
||||
|
@ -90,20 +88,20 @@ func (s *Server) newResponse(r *http.Request) (Response, error) {
|
|||
hostname, _ = s.LookupAddr(ip)
|
||||
}
|
||||
var autonomousSystemNumber string
|
||||
if(asn.AutonomousSystemNumber > 0) {
|
||||
if asn.AutonomousSystemNumber > 0 {
|
||||
autonomousSystemNumber = "AS" + strconv.FormatUint(uint64(asn.AutonomousSystemNumber), 10);
|
||||
}
|
||||
return Response{
|
||||
IP: ip,
|
||||
IPDecimal: ipDecimal,
|
||||
Country: country.Name,
|
||||
CountryISO: country.ISO,
|
||||
IsInEuropeanUnion: country.IsInEuropeanUnion,
|
||||
City: city.Name,
|
||||
Hostname: hostname,
|
||||
LocationLatitude: city.Latitude,
|
||||
LocationLongitude: city.Longitude,
|
||||
AutonomousSystemNumber: autonomousSystemNumber,
|
||||
IP: ip,
|
||||
IPDecimal: ipDecimal,
|
||||
Country: country.Name,
|
||||
CountryISO: country.ISO,
|
||||
IsInEuropeanUnion: country.IsInEuropeanUnion,
|
||||
City: city.Name,
|
||||
Hostname: hostname,
|
||||
LocationLatitude: city.Latitude,
|
||||
LocationLongitude: city.Longitude,
|
||||
AutonomousSystemNumber: autonomousSystemNumber,
|
||||
AutonomousSystemOrganization: asn.AutonomousSystemOrganization,
|
||||
}, nil
|
||||
}
|
||||
|
@ -280,7 +278,6 @@ func (s *Server) Handler() http.Handler {
|
|||
// JSON
|
||||
r.Route("GET", "/", s.JSONHandler).Header("Accept", jsonMediaType)
|
||||
r.Route("GET", "/json", s.JSONHandler)
|
||||
|
||||
r.RoutePrefix("GET", "/json/", s.JSONHandler)
|
||||
|
||||
// CLI
|
||||
|
@ -312,4 +309,4 @@ func (s *Server) ListenAndServe(addr string) error {
|
|||
func FloatToString(input_num float64) string {
|
||||
// to convert a float number to a string
|
||||
return strconv.FormatFloat(input_num, 'f', 6, 64)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,26 +15,26 @@ type Client interface {
|
|||
}
|
||||
|
||||
type Country struct {
|
||||
Name string
|
||||
ISO string
|
||||
Name string
|
||||
ISO string
|
||||
IsInEuropeanUnion bool
|
||||
}
|
||||
|
||||
type City struct {
|
||||
Name string
|
||||
Latitude float64
|
||||
Name string
|
||||
Latitude float64
|
||||
Longitude float64
|
||||
}
|
||||
|
||||
type ASN struct {
|
||||
AutonomousSystemNumber uint
|
||||
AutonomousSystemNumber uint
|
||||
AutonomousSystemOrganization string
|
||||
}
|
||||
|
||||
type geoip struct {
|
||||
country *geoip2.Reader
|
||||
city *geoip2.Reader
|
||||
asn *geoip2.Reader
|
||||
asn *geoip2.Reader
|
||||
}
|
||||
|
||||
func New(countryDB, cityDB, asnDB string) (Client, error) {
|
||||
|
@ -132,4 +132,4 @@ func (g *geoip) ASN(ip net.IP) (ASN, error) {
|
|||
|
||||
func (g *geoip) IsEmpty() bool {
|
||||
return g.country == nil && g.city == nil
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue