Rework complete project

This commit is contained in:
Tom Neuber 2023-12-19 13:56:03 +01:00
parent 868965a072
commit aebf7447c6
Signed by: tom
GPG key ID: F17EFE4272D89FF6
18 changed files with 2237 additions and 1980 deletions

30
pkg/geoloc/static.go Normal file
View file

@ -0,0 +1,30 @@
package geoloc
import (
"fmt"
"math"
"net"
"strings"
"github.com/praserx/ipconv"
)
func GetCountry(input string) *IPInfo {
if c, exists := countries[strings.ToUpper(input)]; exists {
return &c
}
return nil
}
func GetIPInfo(ipaddress string) (uint, error) {
ip := net.ParseIP(ipaddress)
if ip == nil {
return 0, fmt.Errorf("no valid IP address")
}
ipnum, err := ipconv.IPv4ToInt(ip)
if err != nil {
return 0, err
}
ipnumfrom := uint(math.Floor(float64(ipnum)/float64(256))) * 256
return ipnumfrom, nil
}