master v1.0.34
李光春 2 years ago
parent 8b0cd6dfee
commit a24d5383fb

@ -1,3 +1,3 @@
package goip package goip
const Version = "1.0.33" const Version = "1.0.34"

@ -29,7 +29,7 @@ func (c *Client) Query(ipAddress net.IP) (result QueryResult, err error) {
if err != nil { if err != nil {
return result, err return QueryResult{}, err
} }
c.firstIndexPtr = getLong(dbBuff, 0) c.firstIndexPtr = getLong(dbBuff, 0)
@ -39,7 +39,7 @@ func (c *Client) Query(ipAddress net.IP) (result QueryResult, err error) {
ip, err := ip2long(result.Ip) ip, err := ip2long(result.Ip)
if err != nil { if err != nil {
return result, err return QueryResult{}, err
} }
h := c.totalBlocks h := c.totalBlocks
@ -62,12 +62,12 @@ func (c *Client) Query(ipAddress net.IP) (result QueryResult, err error) {
} }
} }
if dataPtr == 0 { if dataPtr == 0 {
return result, errors.New("not found") return QueryResult{}, errors.New("not found")
} }
dataLen := (dataPtr >> 24) & 0xFF dataLen := (dataPtr >> 24) & 0xFF
dataPtr = dataPtr & 0x00FFFFFF dataPtr = dataPtr & 0x00FFFFFF
result = getIpInfo(result.Ip, getLong(dbBuff, dataPtr), dbBuff[(dataPtr)+4:dataPtr+dataLen]) result = getIpInfo(result.Ip, getLong(dbBuff, dataPtr), dbBuff[(dataPtr)+4:dataPtr+dataLen])
return result, nil
return result, nil
} }

@ -32,6 +32,9 @@ func (c *Client) Query(ipAddress net.IP) (result QueryResult, err error) {
result.Ip = ipAddress.String() result.Ip = ipAddress.String()
result.Country = split[0] result.Country = split[0]
if result.Country == "0" {
result.Country = ""
}
result.Province = split[2] result.Province = split[2]
if result.Province == "0" { if result.Province == "0" {
result.Province = "" result.Province = ""

Loading…
Cancel
Save