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