Merge pull request #581 from trheyi/main

Refactor WithGlobal method to handle nil data
This commit is contained in:
Max 2024-02-17 21:35:45 +08:00 committed by GitHub
commit 56a4de0458
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -321,7 +321,14 @@ func (ctx *Context) With(context context.Context) *Context {
// WithGlobal with the global data
func (ctx *Context) WithGlobal(data map[string]interface{}) *Context {
ctx.global = data
if data != nil {
if ctx.global == nil {
ctx.global = map[string]interface{}{}
}
for k, v := range data {
ctx.global[k] = v
}
}
return ctx
}