Remove unnecessary imports

This commit is contained in:
Martin Polden
2018-02-10 18:10:16 +01:00
parent da3502d429
commit 8b1d263e58
3 changed files with 13 additions and 16 deletions

View File

@ -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()
}

View File

@ -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)
}
}