From bb07f328b187a8adb1b400253817b56176cea385 Mon Sep 17 00:00:00 2001 From: kkHAIKE Date: Mon, 19 Sep 2022 16:18:57 +0800 Subject: [PATCH] update README.md --- README.md | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 968340f..368e97f 100644 --- a/README.md +++ b/README.md @@ -71,8 +71,8 @@ func call8() { ``` ## Tips - -You can break ctx inheritance by this way, eg: [issue](https://github.com/kkHAIKE/contextcheck/issues/2). +### need break ctx inheritance +eg: [issue](https://github.com/kkHAIKE/contextcheck/issues/2). ```go func call1(ctx context.Context) { @@ -94,6 +94,7 @@ func NoInheritCancel(_ context.Context) (context.Context,context.CancelFunc) { } ``` +### skip check specify function You can add `// nolint: contextcheck` in function decl doc comment, to skip this linter in some false-positive case. ```go @@ -111,6 +112,25 @@ func call3() { } ``` +### force mark specify function have server-side http.Request parameter +default behavior is mark http.HandlerFunc only. + +```go +// @contextcheck(req_has_ctx) +func writeErr(w http.ResponseWriter, r *http.Request, err error) { + doSomeThing(r.Context()) +} + +func handler(w http.ResponseWriter, r *http.Request) { + ... + if err != nil { + writeErr(w, r, err) + return + } + ... +} +``` + ## Installation You can get `contextcheck` by `go get` command.