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

请教关于StdContext的一个疑问 #103

Open
0x4c5 opened this issue Jun 2, 2023 · 0 comments
Open

请教关于StdContext的一个疑问 #103

0x4c5 opened this issue Jun 2, 2023 · 0 comments

Comments

@0x4c5
Copy link

0x4c5 commented Jun 2, 2023

源代码位置:https://github.com/xinliangnote/go-gin-api/blob/master/internal/pkg/core/context.go:line 392
// RequestContext (包装 Trace + Logger) 获取请求的 context (当client关闭后,会自动canceled)
func (c *context) RequestContext() StdContext {
return StdContext{
//c.ctx.Request.Context(),
stdctx.Background(),
c.Trace(),
c.Logger(),
}
}

为何不用c.ctx.Request.Context();个人理解一个请求应该保持一个ctx,这样在请求退出的时候,会保证所有协程都收到结束指令;为何要用一个全新的ctx呢?还望大佬给解惑🙏🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant