v0.0.213 inject gin key value pairs into context

This commit is contained in:
2023-07-27 09:46:06 +02:00
parent 647ec64c3b
commit f0c5b36ea9
2 changed files with 9 additions and 2 deletions

View File

@@ -14,6 +14,9 @@ type AppContext struct {
}
func CreateAppContext(g *gin.Context, innerCtx context.Context, cancelFn context.CancelFunc) *AppContext {
for key, value := range g.Keys {
context.WithValue(innerCtx, key, value)
}
return &AppContext{
inner: innerCtx,
cancelFunc: cancelFn,
@@ -38,6 +41,10 @@ func (ac *AppContext) Value(key any) any {
return ac.inner.Value(key)
}
func (ac *AppContext) Set(key, value any) {
context.WithValue(ac.inner, key, value)
}
func (ac *AppContext) Cancel() {
ac.cancelled = true
ac.cancelFunc()