package geoloc import ( "errors" "math" "net" "github.com/praserx/ipconv" ) var ErrNoValidIP = errors.New("no valid IP address") func CalculateIPNum(ipaddress string) (uint, error) { ip := net.ParseIP(ipaddress) if ip == nil { return 0, ErrNoValidIP } ipnum, err := ipconv.IPv4ToInt(ip) if err != nil { return 0, err } ipnumfrom := uint(math.Floor(float64(ipnum)/float64(CalculationValue))) * CalculationValue return ipnumfrom, nil }