country-geo-locations/pkg/geoloc/static.go
Tom Neuber 8215e1f13a
All checks were successful
ci/woodpecker/push/lint Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/deploy Pipeline was successful
refactor: restructure project
2024-11-26 13:35:54 +01:00

24 lines
454 B
Go

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
}