mirror of https://github.com/go-sonic/sonic.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
799 B
Go
37 lines
799 B
Go
package template
|
|
|
|
type Model map[string]interface{}
|
|
|
|
func (m Model) AddAttribute(name string, attribute any) {
|
|
m[name] = attribute
|
|
}
|
|
|
|
func (m Model) GetAttribute(name string) any {
|
|
return m[name]
|
|
}
|
|
|
|
func (m Model) ContainsAttribute(name string) bool {
|
|
_, ok := m[name]
|
|
return ok
|
|
}
|
|
|
|
func (m Model) AddAllAttributes(attributes map[string]any) {
|
|
if attributes == nil {
|
|
return
|
|
}
|
|
for key, value := range attributes {
|
|
m[key] = value
|
|
}
|
|
}
|
|
|
|
// MergeAttributes
|
|
// Copy all attributes in the supplied {@code Map} into this {@code Map},
|
|
// with existing objects of the same name taking precedence (i.e. not getting replaced).
|
|
func (m Model) MergeAttributes(attributes map[string]any) {
|
|
for name, value := range attributes {
|
|
if !m.ContainsAttribute(name) {
|
|
m.AddAttribute(name, value)
|
|
}
|
|
}
|
|
}
|