Skip to content

Commit 2f34f46

Browse files
authored
Merge pull request #1 from ldez/fix/redundant-type-conv
fix: redundant type conversion
2 parents c7bd671 + 7690ffa commit 2f34f46

4 files changed

Lines changed: 31 additions & 32 deletions

File tree

client/client.go

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -64,25 +64,25 @@ type Client struct {
6464

6565
// NewClient returns a prepared API client.
6666
func 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.
138135
func (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
}

storage/block_volume_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (c *BlockVolumeClient) List(params *BlockVolumeParams) (*BlockVolumeList, e
5050
if err != nil {
5151
return nil, err
5252
}
53-
return list, err
53+
return list, nil
5454
}
5555

5656
// Update will update a block volume.

storm/config_client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ func (c *ConfigClient) Details(id string) (*Config, error) {
2828

2929
// List fetches a list of storm configs.
3030
func (c *ConfigClient) List(params ConfigListParams) (*ConfigList, error) {
31-
configList := &ConfigList{}
31+
var configList ConfigList
3232

3333
err := c.Backend.Call("v1/Storm/Config/list", params, configList)
3434
if err != nil {
3535
return nil, err
3636
}
3737

38-
return configList, nil
38+
return &configList, nil
3939
}

types/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ func (fi *FlexInt) UnmarshalJSON(b []byte) error {
3939
if b[0] != '"' {
4040
return json.Unmarshal(b, (*int)(fi))
4141
}
42+
4243
var s string
4344
if err := json.Unmarshal(b, &s); err != nil {
4445
return err
4546
}
47+
4648
i, err := strconv.Atoi(s)
4749
if err != nil {
4850
return err

0 commit comments

Comments
 (0)