Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: notify when the request.Context is not used #5

Closed
komuw opened this issue Mar 29, 2022 · 2 comments
Closed

proposal: notify when the request.Context is not used #5

komuw opened this issue Mar 29, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@komuw
Copy link

komuw commented Mar 29, 2022

Go is frequently used for servers. And as such http.Handler is used often.

Given the following code;

package main

import (
	"context"
	"net/http"
)
func foo(ctx context.Context, a, b int) {}

func myHandler(w http.ResponseWriter, r *http.Request) {
	foo(context.Background(), 2, 33)
}

func main() {}

I think contextcheck should error with a message like;
Non-inherited new context, use r.Context() instead

And to resolve the error, you would have to do:

foo(r.Context(), 2, 33)
@komuw komuw changed the title notify when the request.Context is not used proposal: notify when the request.Context is not used Mar 29, 2022
@kkHAIKE kkHAIKE added the duplicate This issue or pull request already exists label May 15, 2022
@kkHAIKE kkHAIKE closed this as completed May 15, 2022
@kkHAIKE kkHAIKE removed the duplicate This issue or pull request already exists label May 15, 2022
@kkHAIKE kkHAIKE reopened this May 15, 2022
@kkHAIKE kkHAIKE added the enhancement New feature or request label May 15, 2022
@kkHAIKE
Copy link
Owner

kkHAIKE commented May 15, 2022

good idea 😊

@kkHAIKE
Copy link
Owner

kkHAIKE commented Aug 16, 2022

Done in new version, golangci/golangci-lint#3102

@kkHAIKE kkHAIKE closed this as completed Aug 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants