Rework complete project
This commit is contained in:
parent
868965a072
commit
aebf7447c6
18 changed files with 2237 additions and 1980 deletions
30
pkg/geoloc/static.go
Normal file
30
pkg/geoloc/static.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue