diff --git a/http/http.go b/http/http.go index 8e9b96d..7ae0340 100644 --- a/http/http.go +++ b/http/http.go @@ -10,10 +10,8 @@ import ( "github.com/mpolden/ipd/useragent" "github.com/sirupsen/logrus" - "math/big" "net" "net/http" - "path/filepath" "strconv" "strings" @@ -38,12 +36,12 @@ type Server struct { } type Response struct { - IP net.IP `json:"ip"` - IPDecimal *big.Int `json:"ip_decimal"` - Country string `json:"country,omitempty"` - CountryISO string `json:"country_iso,omitempty"` - City string `json:"city,omitempty"` - Hostname string `json:"hostname,omitempty"` + IP net.IP `json:"ip"` + IPDecimal uint64 `json:"ip_decimal"` + Country string `json:"country,omitempty"` + CountryISO string `json:"country_iso,omitempty"` + City string `json:"city,omitempty"` + Hostname string `json:"hostname,omitempty"` } type PortResponse struct { @@ -194,7 +192,7 @@ func (s *Server) DefaultHandler(w http.ResponseWriter, r *http.Request) *appErro if err != nil { return internalServerError(err) } - t, err := template.New(filepath.Base(s.Template)).ParseFiles(s.Template) + t, err := template.ParseFiles(s.Template) if err != nil { return internalServerError(err) } diff --git a/iputil/iputil.go b/iputil/iputil.go index ba5afa5..76e8500 100644 --- a/iputil/iputil.go +++ b/iputil/iputil.go @@ -26,12 +26,12 @@ func LookupPort(ip net.IP, port uint64) error { return nil } -func ToDecimal(ip net.IP) *big.Int { +func ToDecimal(ip net.IP) uint64 { i := big.NewInt(0) if to4 := ip.To4(); to4 != nil { i.SetBytes(to4) } else { i.SetBytes(ip) } - return i + return i.Uint64() } diff --git a/iputil/iputil_test.go b/iputil/iputil_test.go index 2a04e10..abe8c94 100644 --- a/iputil/iputil_test.go +++ b/iputil/iputil_test.go @@ -1,7 +1,6 @@ package iputil import ( - "math/big" "net" "testing" ) @@ -9,14 +8,14 @@ import ( func TestToDecimal(t *testing.T) { var tests = []struct { in string - out *big.Int + out uint64 }{ - {"127.0.0.1", big.NewInt(2130706433)}, - {"::1", big.NewInt(1)}, + {"127.0.0.1", 2130706433}, + {"::1", 1}, } for _, tt := range tests { i := ToDecimal(net.ParseIP(tt.in)) - if i.Cmp(tt.out) != 0 { + if tt.out != i { t.Errorf("Expected %d, got %d for IP %s", tt.out, i, tt.in) } }