-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
60 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package txlbs | ||
|
||
import ( | ||
"context" | ||
"net/url" | ||
) | ||
|
||
// IPLocationResponse IP定位回复 | ||
type IPLocationResponse struct { | ||
Meta | ||
Result struct { | ||
IP string `json:"ip"` | ||
Location struct { | ||
Lng float64 `json:"lng"` | ||
Lat float64 `json:"lat"` | ||
} `json:"location"` | ||
AdInfo struct { | ||
Nation string `json:"nation"` | ||
Province string `json:"province"` | ||
City string `json:"city"` | ||
Adcode int `json:"adcode"` | ||
} `json:"ad_info"` | ||
} `json:"result"` | ||
} | ||
|
||
// IPLocation 定位查询 | ||
func (c *Client) IPLocation(ctx context.Context, ip string) (*IPLocationResponse, error) { | ||
v := url.Values{} | ||
if ip != "" { | ||
v.Set("ip", ip) | ||
} | ||
v, err := c.signatureQueryParameter(v, string(ipLocation)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
r := c.ca.NewRequest().WithPath(ipLocation.Full(v.Encode())) | ||
resp, err := c.ca.Do(ctx, r) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var dr IPLocationResponse | ||
if err := resp.DecodeFromJSON(&dr); err != nil { | ||
return nil, err | ||
} | ||
return &dr, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package txlbs | ||
|
||
// Meta includes common response info. | ||
type Meta struct { | ||
Status int `json:"status"` | ||
Message string `json:"message"` | ||
} | ||
|
||
// Success means a valid response. | ||
func (r *Meta) Success() bool { | ||
return r != nil && r.Status == 0 | ||
} |