@@ -9,21 +9,22 @@ import (
99 "io/ioutil"
1010 "net"
1111 "net/http"
12+ "net/url"
1213 "runtime"
1314 "time"
1415
1516 "github.com/pkg/errors"
1617)
1718
1819// Version is the package version
19- const Version = "0.4.1 "
20+ const Version = "0.5.0 "
2021
2122// fqpn is the Fully Qualified Package Name for use in the client's User-Agent
2223const fqpn = "github.com/theckman/go-ipdata"
2324
2425const (
25- apiEndpoint = "https://api.ipdata.co/"
26- apiAuthHeader = "api-key"
26+ apiEndpoint = "https://api.ipdata.co/"
27+ apiAuthParam = "api-key"
2728)
2829
2930var userAgent = fmt .Sprintf (
@@ -62,7 +63,7 @@ func (c Client) Request(ip string) (*http.Response, error) {
6263 // action request
6364 resp , err := c .c .Do (req )
6465 if err != nil {
65- return nil , errors .Wrapf (err , "http request to %q failed" , req .URL .String () )
66+ return nil , errors .Wrapf (err , "http request to %q failed" , req .URL .Scheme + "://" + req . URL . Host + req . URL . Path )
6667 }
6768
6869 switch resp .StatusCode {
@@ -82,7 +83,7 @@ func (c Client) Request(ip string) (*http.Response, error) {
8283
8384 if resp .StatusCode == http .StatusTooManyRequests {
8485 rerr := rateErr {r : true , m : string (body )}
85- return nil , errors .Wrapf (rerr , "request for %q failed (ratelimited)" )
86+ return nil , errors .Wrapf (rerr , "request for %q failed (ratelimited)" , req . URL . String () )
8687 }
8788
8889 return nil , errors .Errorf ("request for %q failed: %s" , ip , string (body ))
@@ -92,27 +93,6 @@ func (c Client) Request(ip string) (*http.Response, error) {
9293 }
9394}
9495
95- // LookupRaw takes an IP address to look up the details for. An empty string
96- // means you want the information about the current node's public IP address.
97- //
98- // This method is a little more performant than Lookup as it does not convert
99- // the RawIP struct to an IP struct.
100- func (c Client ) LookupRaw (ip string ) (RawIP , error ) {
101- resp , err := c .Request (ip )
102- if err != nil {
103- return RawIP {}, err
104- }
105-
106- defer resp .Body .Close ()
107-
108- rip , err := DecodeRawIP (resp .Body )
109- if err != nil {
110- return RawIP {}, err
111- }
112-
113- return rip , nil
114- }
115-
11696// Lookup takes an IP address to look up the details for. An empty string means
11797// you want the information about the current node's pubilc IP address.
11898func (c Client ) Lookup (ip string ) (IP , error ) {
@@ -131,8 +111,8 @@ func (c Client) Lookup(ip string) (IP, error) {
131111 return pip , nil
132112}
133113
134- func newRequest (url , apiKey string ) (* http.Request , error ) {
135- req , err := http .NewRequest (http .MethodGet , url , nil )
114+ func newRequest (urlStr , apiKey string ) (* http.Request , error ) {
115+ req , err := http .NewRequest (http .MethodGet , urlStr , nil )
136116 if err != nil {
137117 return nil , err
138118 }
@@ -141,7 +121,8 @@ func newRequest(url, apiKey string) (*http.Request, error) {
141121
142122 // set the api key header (if set)
143123 if len (apiKey ) > 0 {
144- req .Header .Set (apiAuthHeader , apiKey )
124+ q := url.Values {apiAuthParam : []string {apiKey }}
125+ req .URL .RawQuery = q .Encode ()
145126 }
146127
147128 return req , nil
0 commit comments