Refactor WithGlobal method to handle nil data

This commit is contained in:
Max 2024-02-17 21:34:32 +08:00
parent 6b90d097e2
commit 8095996c95

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
}