@@ -56,75 +56,23 @@ golangci-lint run --enable-only noctx
56
56
57
57
## net/http package
58
58
### Detection rules
59
-
60
- - Executing the following functions
61
- https://github.com/sonatard/noctx/blob/9a514098df3f8a88e0fd6949320c4e0aa51b520c/ngfunc/main.go#L15-L26
62
-
63
- ### How to fix
64
-
65
- - use ` http.NewRequestWithContext ` function instead of using ` http.NewRequest ` function.
66
- - Send http request using ` (*http.Client).Do(*http.Request) ` method.
67
-
68
- If your library already provides functions that don't accept context, you define a new function that accepts context and make the existing function a wrapper for a new function.
69
-
70
- ``` go
71
- // Before fix code
72
- // Sending an HTTP request but not accepting context
73
- func Send (body io .Reader ) error {
74
- req,err := http.NewRequest (http.MethodPost , " http://example.com" , body)
75
- if err != nil {
76
- return err
77
- }
78
- _, err = http.DefaultClient .Do (req)
79
- if err != nil {
80
- return err
81
- }
82
-
83
- return nil
84
- }
85
- ```
86
-
87
- ``` go
88
- // After fix code
89
- func Send (body io .Reader ) error {
90
- // Pass context.Background() to SendWithContext
91
- return SendWithContext (context.Background (), body)
92
- }
93
-
94
- // Sending an HTTP request and accepting context
95
- func SendWithContext (ctx context .Context , body io .Reader ) error {
96
- // Change NewRequest to NewRequestWithContext and pass context to it
97
- req , err := http.NewRequestWithContext (ctx, http.MethodPost , " http://example.com" , body)
98
- if err != nil {
99
- return err
100
- }
101
- _, err = http.DefaultClient .Do (req)
102
- if err != nil {
103
- return err
104
- }
105
-
106
- return nil
107
- }
108
- ```
59
+ https://github.com/sonatard/noctx/blob/127ded2eb4422a885f6e9c97e95cc9b89b7f1163/ngfunc/main.go#L17-L26
109
60
110
61
### Detection sample
111
-
112
62
https://github.com/sonatard/noctx/blob/9a514098df3f8a88e0fd6949320c4e0aa51b520c/testdata/src/http_client/http_client.go#L11
113
63
https://github.com/sonatard/noctx/blob/9a514098df3f8a88e0fd6949320c4e0aa51b520c/testdata/src/http_request/http_request.go#L17
114
64
115
65
### Reference
116
-
117
66
- [ net/http - NewRequest] ( https://pkg.go.dev/net/http#NewRequest )
118
67
- [ net/http - NewRequestWithContext] ( https://pkg.go.dev/net/http#NewRequestWithContext )
119
68
- [ net/http - Request.WithContext] ( https://pkg.go.dev/net/http#Request.WithContext )
120
69
-
121
- ## database/sqlpackage
70
+ ## database/sql package
122
71
### Detection rules
123
-
124
- - Executing the following functions
72
+ https://github.com/sonatard/noctx/blob/127ded2eb4422a885f6e9c97e95cc9b89b7f1163/ngfunc/main.go#L29-L37
125
73
126
74
### Detection sample
127
-
75
+ https://github.com/sonatard/noctx/blob/6e0f6bb8de1bd8a3c6e73439614927fd59aa0a8a/testdata/src/sql/sql.go#L13
128
76
129
77
### Reference
130
78
- [ database/sql] ( https://pkg.go.dev/database/sql )
0 commit comments