Update metadata.go (#2015)

pull/2021/head
songzhibin97 3 years ago committed by GitHub
parent 2eb615b38a
commit 1dfac59204
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      metadata/metadata.go

@ -24,8 +24,7 @@ func New(mds ...map[string]string) Metadata {
// Get returns the value associated with the passed key. // Get returns the value associated with the passed key.
func (m Metadata) Get(key string) string { func (m Metadata) Get(key string) string {
k := strings.ToLower(key) return m[strings.ToLower(key)]
return m[k]
} }
// Set stores the key-value pair. // Set stores the key-value pair.
@ -33,15 +32,13 @@ func (m Metadata) Set(key string, value string) {
if key == "" || value == "" { if key == "" || value == "" {
return return
} }
k := strings.ToLower(key) m[strings.ToLower(key)] = value
m[k] = value
} }
// Range iterate over element in metadata. // Range iterate over element in metadata.
func (m Metadata) Range(f func(k, v string) bool) { func (m Metadata) Range(f func(k, v string) bool) {
for k, v := range m { for k, v := range m {
ret := f(k, v) if !f(k, v) {
if !ret {
break break
} }
} }

Loading…
Cancel
Save