Ensure non-nil maps
This commit is contained in:
		
							
								
								
									
										14
									
								
								namespace.go
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								namespace.go
									
									
									
									
									
								
							| @@ -43,7 +43,13 @@ func New() *Namespace { | ||||
| func (n *Namespace) WithVarMap(m map[string]any) *Namespace { | ||||
| 	n.mu.Lock() | ||||
| 	defer n.mu.Unlock() | ||||
| 	n.vars = m | ||||
|  | ||||
| 	if m == nil { | ||||
| 		n.vars = map[string]any{} | ||||
| 	} else { | ||||
| 		n.vars = m | ||||
| 	} | ||||
|  | ||||
| 	return n | ||||
| } | ||||
|  | ||||
| @@ -52,10 +58,10 @@ func (n *Namespace) WithTagMap(m map[string]Tag) *Namespace { | ||||
| 	n.mu.Lock() | ||||
| 	defer n.mu.Unlock() | ||||
|  | ||||
| 	if m != nil { | ||||
| 		n.tags = m | ||||
| 	} else { | ||||
| 	if m == nil { | ||||
| 		n.tags = map[string]Tag{} | ||||
| 	} else { | ||||
| 		n.tags = m | ||||
| 	} | ||||
|  | ||||
| 	return n | ||||
|   | ||||
							
								
								
									
										12
									
								
								salix.go
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								salix.go
									
									
									
									
									
								
							| @@ -67,17 +67,21 @@ type Template struct { | ||||
|  | ||||
| // WithVarMap returns a copy of the template with its variable map set to m. | ||||
| func (t Template) WithVarMap(m map[string]any) Template { | ||||
| 	t.vars = m | ||||
| 	if m == nil { | ||||
| 		t.vars = map[string]any{} | ||||
| 	} else { | ||||
| 		t.vars = m | ||||
| 	} | ||||
| 	return t | ||||
| } | ||||
|  | ||||
| // WithTagMap returns a copy of the template with its tag map set to m. | ||||
| func (t Template) WithTagMap(m map[string]Tag) Template { | ||||
| 	// Make sure the tag map is never nil to avoid panics | ||||
| 	if m == nil { | ||||
| 		m = map[string]Tag{} | ||||
| 		t.tags = map[string]Tag{} | ||||
| 	} else { | ||||
| 		t.tags = m | ||||
| 	} | ||||
| 	t.tags = m | ||||
| 	return t | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user