Refactor WithGlobal method to handle nil data
This commit is contained in:
parent
6b90d097e2
commit
8095996c95
1 changed files with 8 additions and 1 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue