mirror of https://github.com/mpolden/echoip
gofmt -- hopefuly what works
This commit is contained in:
parent
02619025af
commit
79e3d6a9be
|
@ -48,29 +48,29 @@ func main() {
|
|||
var headers multiValueFlag
|
||||
flag.Var(&headers, "H", "Header to trust for remote IP, if present (e.g. X-Real-IP)")
|
||||
flag.Parse()
|
||||
|
||||
|
||||
if len(flag.Args()) != 0 {
|
||||
flag.Usage()
|
||||
return
|
||||
}
|
||||
|
||||
var parser parser.Parser
|
||||
if (*service == "geoip") {
|
||||
if *service == "geoip" {
|
||||
geo, err := geo.Open(*countryFile, *cityFile, *asnFile)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
parser = &geo
|
||||
}
|
||||
|
||||
if (*service == "ipstack") {
|
||||
if err := ipstackApi.Init(ipstackApiKey); err != nil {
|
||||
}
|
||||
|
||||
if *service == "ipstack" {
|
||||
if err := ipstackApi.Init(ipstackApiKey); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
ips := ipstack.IPStack{}
|
||||
parser = &ips
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
cache := http.NewCache(*cacheSize)
|
||||
server := http.New(parser, cache, *profile)
|
||||
server.IPHeaders = headers
|
||||
|
|
|
@ -172,8 +172,7 @@
|
|||
<p>
|
||||
This information is provided from the GeoLite2 database created by
|
||||
MaxMind, available from
|
||||
<a href="https://www.maxmind.com">www.maxmind.com</a>
|
||||
</p>
|
||||
<a href="https://www.maxmind.com">www.maxmind.com</a> </p>
|
||||
{{ end}} {{ if .Service == "ipstack" }}
|
||||
<p>
|
||||
This information is provided from
|
||||
|
|
|
@ -296,7 +296,7 @@ func (s *Server) DefaultHandler(w http.ResponseWriter, r *http.Request) *appErro
|
|||
}
|
||||
|
||||
var data = struct {
|
||||
parser.Response
|
||||
parser.Response
|
||||
Host string
|
||||
BoxLatTop float64
|
||||
BoxLatBottom float64
|
||||
|
@ -316,7 +316,7 @@ func (s *Server) DefaultHandler(w http.ResponseWriter, r *http.Request) *appErro
|
|||
s.LookupPort != nil,
|
||||
s.Sponsor,
|
||||
}
|
||||
|
||||
|
||||
if err := t.Execute(w, &data); err != nil {
|
||||
return internalServerError(err)
|
||||
}
|
||||
|
|
|
@ -81,23 +81,24 @@ func (g *geoip) Parse(ip net.IP, hostname string) (parser.Response, error) {
|
|||
autonomousSystemNumber = fmt.Sprintf("AS%d", asn.AutonomousSystemNumber)
|
||||
}
|
||||
return parser.Response{
|
||||
Service: "ipstack",
|
||||
IP: ip,
|
||||
IPDecimal: ipDecimal,
|
||||
Country: country.Name,
|
||||
CountryISO: country.ISO,
|
||||
CountryEU: country.IsEU,
|
||||
RegionName: city.RegionName,
|
||||
RegionCode: city.RegionCode,
|
||||
MetroCode: city.MetroCode,
|
||||
PostalCode: city.PostalCode,
|
||||
City: city.Name,
|
||||
Latitude: city.Latitude,
|
||||
Longitude: city.Longitude,
|
||||
Timezone: city.Timezone,
|
||||
ASN: autonomousSystemNumber,
|
||||
ASNOrg: asn.AutonomousSystemOrganization,
|
||||
Hostname: hostname,
|
||||
UsingGeoIP: true,
|
||||
UsingIPStack: false,
|
||||
IP: ip,
|
||||
IPDecimal: ipDecimal,
|
||||
Country: country.Name,
|
||||
CountryISO: country.ISO,
|
||||
CountryEU: country.IsEU,
|
||||
RegionName: city.RegionName,
|
||||
RegionCode: city.RegionCode,
|
||||
MetroCode: city.MetroCode,
|
||||
PostalCode: city.PostalCode,
|
||||
City: city.Name,
|
||||
Latitude: city.Latitude,
|
||||
Longitude: city.Longitude,
|
||||
Timezone: city.Timezone,
|
||||
ASN: autonomousSystemNumber,
|
||||
ASNOrg: asn.AutonomousSystemOrganization,
|
||||
Hostname: hostname,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -14,32 +14,30 @@ type IPStack struct {
|
|||
}
|
||||
|
||||
func (ips *IPStack) Parse(ip net.IP, hostname string) (parser.Response, error) {
|
||||
res, err := ipstack.IP(ip.String());
|
||||
res, err := ipstack.IP(ip.String())
|
||||
ips.response = res
|
||||
if err != nil {
|
||||
return parser.Response{}, err
|
||||
if err != nil {
|
||||
return parser.Response{}, err
|
||||
}
|
||||
fmt.Printf("%+v\n", res)
|
||||
|
||||
|
||||
ipDecimal := iputil.ToDecimal(ip)
|
||||
|
||||
|
||||
|
||||
parserResponse := parser.Response{
|
||||
Service: "ipstack",
|
||||
Latitude: float64(res.Latitide),
|
||||
Longitude: float64(res.Longitude),
|
||||
Hostname: hostname,
|
||||
IP: ip,
|
||||
IPDecimal: ipDecimal,
|
||||
Country: res.CountryName,
|
||||
CountryISO: res.CountryCode,
|
||||
RegionName: res.RegionName,
|
||||
RegionCode: res.RegionCode,
|
||||
MetroCode: 0,
|
||||
PostalCode: res.Zip,
|
||||
City: res.City,
|
||||
UsingGeoIP: false,
|
||||
UsingIPStack: true,
|
||||
Latitude: float64(res.Latitide),
|
||||
Longitude: float64(res.Longitude),
|
||||
Hostname: hostname,
|
||||
IP: ip,
|
||||
IPDecimal: ipDecimal,
|
||||
Country: res.CountryName,
|
||||
CountryISO: res.CountryCode,
|
||||
RegionName: res.RegionName,
|
||||
RegionCode: res.RegionCode,
|
||||
MetroCode: 0,
|
||||
PostalCode: res.Zip,
|
||||
City: res.City,
|
||||
}
|
||||
|
||||
if res.Timezone != nil {
|
||||
|
@ -47,7 +45,7 @@ func (ips *IPStack) Parse(ip net.IP, hostname string) (parser.Response, error) {
|
|||
}
|
||||
|
||||
if res.Location != nil {
|
||||
parserResponse.CountryEU = &res.Location.IsEU;
|
||||
parserResponse.CountryEU = &res.Location.IsEU
|
||||
}
|
||||
|
||||
if res.Connection != nil {
|
||||
|
@ -55,7 +53,7 @@ func (ips *IPStack) Parse(ip net.IP, hostname string) (parser.Response, error) {
|
|||
parserResponse.ASN = fmt.Sprintf("AS%d", res.Connection.ASN)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return parserResponse, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -13,22 +13,23 @@ type Parser interface {
|
|||
}
|
||||
|
||||
type Response struct {
|
||||
Service string `json:"database"`
|
||||
IP net.IP `json:"ip"`
|
||||
IPDecimal *big.Int `json:"ip_decimal"`
|
||||
Country string `json:"country,omitempty"`
|
||||
CountryISO string `json:"country_iso,omitempty"`
|
||||
CountryEU *bool `json:"country_eu,omitempty"`
|
||||
RegionName string `json:"region_name,omitempty"`
|
||||
RegionCode string `json:"region_code,omitempty"`
|
||||
MetroCode uint `json:"metro_code,omitempty"`
|
||||
PostalCode string `json:"zip_code,omitempty"`
|
||||
City string `json:"city,omitempty"`
|
||||
Latitude float64 `json:"latitude,omitempty"`
|
||||
Longitude float64 `json:"longitude,omitempty"`
|
||||
Timezone string `json:"time_zone,omitempty"`
|
||||
ASN string `json:"asn,omitempty"`
|
||||
ASNOrg string `json:"asn_org,omitempty"`
|
||||
Hostname string `json:"hostname,omitempty"`
|
||||
UserAgent *useragent.UserAgent `json:"user_agent,omitempty"`
|
||||
UsingGeoIP bool `json:"UsingGeoIP"`
|
||||
UsingIPStack bool `json:"UsingIPStack"`
|
||||
IP net.IP `json:"ip"`
|
||||
IPDecimal *big.Int `json:"ip_decimal"`
|
||||
Country string `json:"country,omitempty"`
|
||||
CountryISO string `json:"country_iso,omitempty"`
|
||||
CountryEU *bool `json:"country_eu,omitempty"`
|
||||
RegionName string `json:"region_name,omitempty"`
|
||||
RegionCode string `json:"region_code,omitempty"`
|
||||
MetroCode uint `json:"metro_code,omitempty"`
|
||||
PostalCode string `json:"zip_code,omitempty"`
|
||||
City string `json:"city,omitempty"`
|
||||
Latitude float64 `json:"latitude,omitempty"`
|
||||
Longitude float64 `json:"longitude,omitempty"`
|
||||
Timezone string `json:"time_zone,omitempty"`
|
||||
ASN string `json:"asn,omitempty"`
|
||||
ASNOrg string `json:"asn_org,omitempty"`
|
||||
Hostname string `json:"hostname,omitempty"`
|
||||
UserAgent *useragent.UserAgent `json:"user_agent,omitempty"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue