Skip to content

Commit 38efa7c

Browse files
committed
Update sql doc
1 parent 127ded2 commit 38efa7c

File tree

1 file changed

+4
-56
lines changed

1 file changed

+4
-56
lines changed

README.md

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -56,75 +56,23 @@ golangci-lint run --enable-only noctx
5656

5757
## net/http package
5858
### 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
10960

11061
### Detection sample
111-
11262
https://github.com/sonatard/noctx/blob/9a514098df3f8a88e0fd6949320c4e0aa51b520c/testdata/src/http_client/http_client.go#L11
11363
https://github.com/sonatard/noctx/blob/9a514098df3f8a88e0fd6949320c4e0aa51b520c/testdata/src/http_request/http_request.go#L17
11464

11565
### Reference
116-
11766
- [net/http - NewRequest](https://pkg.go.dev/net/http#NewRequest)
11867
- [net/http - NewRequestWithContext](https://pkg.go.dev/net/http#NewRequestWithContext)
11968
- [net/http - Request.WithContext](https://pkg.go.dev/net/http#Request.WithContext)
12069
-
121-
## database/sqlpackage
70+
## database/sql package
12271
### Detection rules
123-
124-
- Executing the following functions
72+
https://github.com/sonatard/noctx/blob/127ded2eb4422a885f6e9c97e95cc9b89b7f1163/ngfunc/main.go#L29-L37
12573

12674
### Detection sample
127-
75+
https://github.com/sonatard/noctx/blob/6e0f6bb8de1bd8a3c6e73439614927fd59aa0a8a/testdata/src/sql/sql.go#L13
12876

12977
### Reference
13078
- [database/sql](https://pkg.go.dev/database/sql)

0 commit comments

Comments
 (0)