stream/mts/meta.go: wrote ReadFrom func - still need to write tests for it

This commit is contained in:
saxon 2019-01-31 13:26:16 +10:30
parent 1d9cb57505
commit 9011c090d9
1 changed files with 12 additions and 0 deletions

View File

@ -29,6 +29,7 @@ package mts
import (
"errors"
"strings"
"sync"
)
@ -131,3 +132,14 @@ func (m *Metadata) Encode() []byte {
return m.enc
}
func ReadFrom(d []byte, key string) (string, error) {
entries := strings.Split(string(d), "\t")
for _, entry := range entries {
kv := strings.Split(entry, "=")
if kv[0] == key {
return kv[1], nil
}
}
return "", errors.New("could not find key in metadata")
}