refactor: restructure project
This commit is contained in:
parent
1bde2041e1
commit
8215e1f13a
21 changed files with 850 additions and 269 deletions
|
@ -1,22 +1,24 @@
|
|||
package geoloc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
"math"
|
||||
"net"
|
||||
|
||||
"github.com/praserx/ipconv"
|
||||
)
|
||||
|
||||
func GetIPInfo(ipaddress string) (uint, error) {
|
||||
var ErrNoValidIP = errors.New("no valid IP address")
|
||||
|
||||
func CalculateIPNum(ipaddress string) (uint, error) {
|
||||
ip := net.ParseIP(ipaddress)
|
||||
if ip == nil {
|
||||
return 0, fmt.Errorf("no valid IP address")
|
||||
return 0, ErrNoValidIP
|
||||
}
|
||||
ipnum, err := ipconv.IPv4ToInt(ip)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
ipnumfrom := uint(math.Floor(float64(ipnum)/float64(256))) * 256
|
||||
ipnumfrom := uint(math.Floor(float64(ipnum)/float64(CalculationValue))) * CalculationValue
|
||||
return ipnumfrom, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue