Skip to content

Commit fd19340

Browse files
committed
refactor(lint): refactor linter configuration and improve code clarity
- Remove the `exportloopref` linter from the configuration - Update comments for clarity in the `SetQueryD` function - Change type assertion syntax for better readability - Add context to the HTTP request initialization in the `initTest` function Signed-off-by: appleboy <[email protected]>
1 parent da01cec commit fd19340

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ linters:
77
- dogsled
88
- dupl
99
- errcheck
10-
- exportloopref
1110
- exhaustive
1211
- gochecknoinits
1312
- goconst

gofight.go

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,55 @@
22
//
33
// Details about the gofight project are found in github page:
44
//
5-
// https://github.com/appleboy/gofight
5+
// https://github.com/appleboy/gofight
66
//
77
// Installation:
88
//
9-
// $ go get -u github.com/appleboy/gofight
9+
// $ go get -u github.com/appleboy/gofight
1010
//
1111
// Set Header: You can add custom header via SetHeader func.
1212
//
13-
// SetHeader(gofight.H{
14-
// "X-Version": version,
15-
// })
13+
// SetHeader(gofight.H{
14+
// "X-Version": version,
15+
// })
1616
//
1717
// Set Cookie: You can add custom cookie via SetCookie func.
1818
//
19-
// SetCookie(gofight.H{
20-
// "foo": "bar",
21-
// })
19+
// SetCookie(gofight.H{
20+
// "foo": "bar",
21+
// })
2222
//
2323
// Set query string: Using SetQuery to generate query string data.
2424
//
25-
// SetQuery(gofight.H{
26-
// "a": "1",
27-
// "b": "2",
28-
// })
25+
// SetQuery(gofight.H{
26+
// "a": "1",
27+
// "b": "2",
28+
// })
2929
//
3030
// POST FORM Data: Using SetForm to generate form data.
3131
//
32-
// SetForm(gofight.H{
33-
// "a": "1",
34-
// "b": "2",
35-
// })
32+
// SetForm(gofight.H{
33+
// "a": "1",
34+
// "b": "2",
35+
// })
3636
//
3737
// POST JSON Data: Using SetJSON to generate json data.
3838
//
39-
// SetJSON(gofight.H{
40-
// "a": "1",
41-
// "b": "2",
42-
// })
39+
// SetJSON(gofight.H{
40+
// "a": "1",
41+
// "b": "2",
42+
// })
4343
//
4444
// POST RAW Data: Using SetBody to generate raw data.
4545
//
46-
// SetBody("a=1&b=1")
46+
// SetBody("a=1&b=1")
4747
//
4848
// For more details, see the documentation and example.
49-
//
5049
package gofight
5150

5251
import (
5352
"bytes"
53+
"context"
5454
"encoding/json"
5555
"io"
5656
"log"
@@ -272,23 +272,24 @@ func (rc *RequestConfig) SetPath(str string) *RequestConfig {
272272
}
273273

274274
// SetQueryD supply query string, support query using string array input.
275-
// ex. /reqpath/?Ids[]=E&Ids[]=M usage: IDArray:=[]string{"E","M"} r.GET("reqpath").SetQueryD(gofight.D{`Ids[]`: IDArray})
275+
// ex. /reqpath/?Ids[]=E&Ids[]=M usage:
276+
// IDArray:=[]string{"E","M"} r.GET("reqpath").SetQueryD(gofight.D{`Ids[]`: IDArray})
276277
func (rc *RequestConfig) SetQueryD(query D) *RequestConfig {
277278
var buf strings.Builder
278279
buf.WriteString("?")
279280
for k, v := range query {
280-
switch v.(type) {
281+
switch v := v.(type) {
281282
case string:
282-
buf.WriteString(k + "=" + v.(string))
283+
buf.WriteString(k + "=" + v)
283284
buf.WriteString("&")
284285
case []string:
285-
for _, info := range v.([]string) {
286+
for _, info := range v {
286287
buf.WriteString(k + "=" + info)
287288
buf.WriteString("&")
288289
}
289290
}
290291
}
291-
rc.Path = rc.Path + buf.String()[:len(buf.String())-1]
292+
rc.Path += buf.String()[:len(buf.String())-1]
292293
return rc
293294
}
294295

@@ -337,7 +338,7 @@ func (rc *RequestConfig) initTest() (*http.Request, *httptest.ResponseRecorder)
337338

338339
body := bytes.NewBufferString(rc.Body)
339340

340-
req, _ := http.NewRequest(rc.Method, rc.Path, body)
341+
req, _ := http.NewRequestWithContext(context.Background(), rc.Method, rc.Path, body)
341342
req.RequestURI = req.URL.RequestURI()
342343

343344
if len(qs) > 0 {

0 commit comments

Comments
 (0)