@@ -64,25 +64,25 @@ type Client struct {
6464
6565// NewClient returns a prepared API client.
6666func NewClient (config * Config ) * Client {
67- httpClient := & http.Client {Timeout : time .Duration (time . Duration ( config .Timeout ) * time .Second ) }
67+ httpClient := & http.Client {Timeout : time .Duration (config .Timeout ) * time .Second }
6868
6969 if ! config .SecureTLS {
7070 tr := & http.Transport {
7171 TLSClientConfig : & tls.Config {InsecureSkipVerify : true },
7272 }
7373 httpClient .Transport = tr
7474 }
75- client := & Client {
76- config : config ,
77- httpClient : httpClient }
7875
79- return client
76+ return & Client {
77+ config : config ,
78+ httpClient : httpClient ,
79+ }
8080}
8181
8282// Call takes a path, such as "network/zone/details" and a params structure.
8383// It is recommended that the params be a map[string]interface{}, but you can use
8484// anything that serializes to the right json structure.
85- // A `interface{}` and an error are returned, in typical go fasion .
85+ // A `interface{}` and an error are returned, in typical go fashion .
8686//
8787// Example:
8888// args := map[string]interface{}{
@@ -115,10 +115,7 @@ func (client *Client) Call(method string, params interface{}, into interface{})
115115 }
116116
117117 // Response should be valid, decode it.
118- if err = json .Unmarshal (bsRb , & into ); err != nil {
119- return err
120- }
121- return nil
118+ return json .Unmarshal (bsRb , & into )
122119}
123120
124121// CallRaw is just like Call, except it returns the raw json as a byte slice. However, in contrast to
@@ -137,36 +134,36 @@ func (client *Client) Call(method string, params interface{}, into interface{})
137134// // Check got now for LiquidWeb specific exceptions, as described above.
138135func (client * Client ) CallRaw (method string , params interface {}) ([]byte , error ) {
139136 // api wants the "params" prefix key. Do it here so consumers dont have
140- // to do this everytime .
137+ // to do this every time .
141138 args := map [string ]interface {}{
142139 "params" : params ,
143140 }
144- encodedArgs , encodeErr := json .Marshal (args )
145- if encodeErr != nil {
146- return nil , encodeErr
141+ encodedArgs , err := json .Marshal (args )
142+ if err != nil {
143+ return nil , err
147144 }
145+
148146 // formulate the HTTP POST request
149- url := fmt .Sprintf ("%s/%s" , client .config .URL , method )
150- req , reqErr := http .NewRequest ("POST" , url , bytes .NewReader (encodedArgs ))
151- if reqErr != nil {
152- return nil , reqErr
147+ uri := fmt .Sprintf ("%s/%s" , client .config .URL , method )
148+ req , err := http .NewRequest (http . MethodPost , uri , bytes .NewReader (encodedArgs ))
149+ if err != nil {
150+ return nil , err
153151 }
152+
154153 // HTTP basic auth
155154 req .SetBasicAuth (client .config .Username , client .config .Password )
155+
156156 // make the POST request
157- resp , doErr := client .httpClient .Do (req )
158- if doErr != nil {
159- return nil , doErr
157+ resp , err := client .httpClient .Do (req )
158+ if err != nil {
159+ return nil , err
160160 }
161161 defer resp .Body .Close ()
162- if resp .StatusCode != 200 {
163- return nil , fmt .Errorf ("Bad HTTP response code [%d] from [%s]" , resp .StatusCode , url )
164- }
165- // read the response body into a byte slice
166- bsRb , readErr := ioutil .ReadAll (resp .Body )
167- if readErr != nil {
168- return nil , readErr
162+
163+ if resp .StatusCode != http .StatusOK {
164+ return nil , fmt .Errorf ("bad HTTP response code [%d] from [%s]" , resp .StatusCode , uri )
169165 }
170166
171- return bsRb , nil
167+ // read the response body into a byte slice
168+ return ioutil .ReadAll (resp .Body )
172169}
0 commit comments