mts/meta: created NewFromMap method

This commit is contained in:
Scott 2020-02-18 15:45:48 +10:30
parent 24a4654f6b
commit 6855244424
1 changed files with 11 additions and 0 deletions

View File

@ -90,6 +90,17 @@ func NewWith(data [][2]string) *Data {
return m return m
} }
// NewFromMap creates a meta.Data from a map.
func NewFromMap(data map[string]string) *Data {
m := New()
m.order = make([]string, 0, len(data))
for k, v := range data {
m.data[k] = v
m.order = append(m.order, k)
}
return m
}
// Add adds metadata with key and val. // Add adds metadata with key and val.
func (m *Data) Add(key, val string) { func (m *Data) Add(key, val string) {
m.mu.Lock() m.mu.Lock()