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

[Feature Request] support that the context.Context is passed down #609

Open
yflau opened this issue May 8, 2024 · 0 comments
Open

[Feature Request] support that the context.Context is passed down #609

yflau opened this issue May 8, 2024 · 0 comments

Comments

@yflau
Copy link
Contributor

yflau commented May 8, 2024

需求背景

Now the context.Context will not be passed down on the call path, some functions are difficult to implement, e.g., if I want to associate logs through trace_id, it's impossible.
当前context.Context并未在调用链路上确保传递,因此,一些功能难以实现,例如,通过trace_id实现关联日志的提取无法实现。

提案

To implement this, it seems that many changes to be done, e.g.

  • yaoapp/gou/api.handler
// defaultHandler default handler
func (path Path) defaultHandler(getArgs func(c *gin.Context) []interface{}) func(c *gin.Context) {
	return func(c *gin.Context) {

		ctx, cancel := context.WithCancel(c.Request.Context())  // NOTE: context.Background() -> c.Request.Context()
		defer cancel()
		// defer debug.FreeOSMemory()
                ...
}
  • yaoapp/xun/dbal/query/interfaces.go
type Query interface {
	// defined in the builder.go file
	...
	// defined in the query.go file
	Table(name string) Query
	Get(ctx context.Context, v ...interface{}) ([]xun.R, error) // NOTE: add ctx param
	MustGet(ctx context.Context, v ...interface{}) []xun.R      // NOTE: add ctx param
	...
}
  • corresponding methods of yaoapp/xun/dbal/query/builder.Builder
func (builder *Builder) Get(ctx context.Context, v ...interface{}) ([]xun.R, error) { // NOTE: add ctx param
    // ...
}

额外补充

Add any other context or screenshots about the feature request here.

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