From b6acdacdddb1ab7b407a92744f81d3f6db8c4a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Raunsb=C3=A6k?= Date: Fri, 15 Jun 2018 08:57:10 +0200 Subject: [PATCH] Fix indention --- cmd/ipd/main.go | 2 +- http/http.go | 47 +++++++++++++++++-------------------- iputil/database/database.go | 14 +++++------ 3 files changed, 30 insertions(+), 33 deletions(-) diff --git a/cmd/ipd/main.go b/cmd/ipd/main.go index 41d9b01..9710dfc 100644 --- a/cmd/ipd/main.go +++ b/cmd/ipd/main.go @@ -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"` diff --git a/http/http.go b/http/http.go index 086957d..7a9c37c 100644 --- a/http/http.go +++ b/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) -} \ No newline at end of file +} diff --git a/iputil/database/database.go b/iputil/database/database.go index c87e7d4..3e4220f 100644 --- a/iputil/database/database.go +++ b/iputil/database/database.go @@ -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 -} \ No newline at end of file +}