v0.0.213 inject gin key value pairs into context

This commit is contained in:
Julian Graf 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 { 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{ return &AppContext{
inner: innerCtx, inner: innerCtx,
cancelFunc: cancelFn, cancelFunc: cancelFn,
@ -38,6 +41,10 @@ func (ac *AppContext) Value(key any) any {
return ac.inner.Value(key) return ac.inner.Value(key)
} }
func (ac *AppContext) Set(key, value any) {
context.WithValue(ac.inner, key, value)
}
func (ac *AppContext) Cancel() { func (ac *AppContext) Cancel() {
ac.cancelled = true ac.cancelled = true
ac.cancelFunc() ac.cancelFunc()

View File

@ -1,5 +1,5 @@
package goext package goext
const GoextVersion = "0.0.212" const GoextVersion = "0.0.213"
const GoextVersionTimestamp = "2023-07-26T10:44:26+0200" const GoextVersionTimestamp = "2023-07-27T09:46:06+0200"