mirror of https://bitbucket.org/ausocean/av.git
stream/mts/meta.go: wrote ReadFrom func - still need to write tests for it
This commit is contained in:
parent
1d9cb57505
commit
9011c090d9
|
@ -29,6 +29,7 @@ package mts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -131,3 +132,14 @@ func (m *Metadata) Encode() []byte {
|
||||||
|
|
||||||
return m.enc
|
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")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue