util/net/converter/ip.go

18 lines
268 B
Go
Raw Normal View History

2017-09-11 09:09:01 +00:00
package converter
import (
2017-11-17 10:07:00 +00:00
"fmt"
"net"
2017-09-11 09:09:01 +00:00
)
2017-11-17 10:07:00 +00:00
func IPToInt(ip net.IP) (int32, error) {
switch len(ip) {
case net.IPv4len:
return IPv4ToInt(ip), nil
case net.IPv6len:
return IPv6ToInt(ip), nil
default:
return 0, fmt.Errorf("Net: not supported IP length")
2017-09-11 09:09:01 +00:00
}
}