Add metadata.New back

This commit is contained in:
iamqizhao
2015-01-28 22:49:38 -08:00
parent be58fe3a09
commit f1ef727170
2 changed files with 13 additions and 2 deletions

View File

@ -83,9 +83,20 @@ func DecodeKeyValue(k, v string) (string, string, error) {
return key, string(val), nil
}
// MD is a mapping from metadata keys to values.
// MD is a mapping from metadata keys to values. Users should use the following
// two convenience functions New and Pairs to generate MD.
type MD map[string]string
// New creates a MD from given key-value map.
func New(m map[string]string) MD {
md := MD{}
for k, v := range m {
key, val := encodeKeyValue(k, v)
md[key] = val
}
return md
}
// Pairs returns an MD formed by the mapping of key, value ...
// Pairs panics if len(kv) is odd.
func Pairs(kv ...string) MD {

View File

@ -69,7 +69,7 @@ func TestPairsMD(t *testing.T) {
md MD
}{
{[]string{}, MD{}},
{[]string{"k1", "v1", "k2", binaryValue}, MD(map[string]string{
{[]string{"k1", "v1", "k2", binaryValue}, New(map[string]string{
"k1": "v1",
"k2-bin": "woA=",
})},