This commit is contained in:
Asim 2016-03-29 18:32:16 +01:00
parent cb89b2ebca
commit 17a97e2ef1

View File

@ -57,11 +57,20 @@ func encodeEndpoints(en []*Endpoint) []string {
func decodeEndpoints(tags []string) []*Endpoint {
var en []*Endpoint
// use the first format you find
var ver byte
for _, tag := range tags {
if len(tag) == 0 || tag[0] != 'e' {
continue
}
// check version
if ver > 0 && tag[1] != ver {
continue
}
var e *Endpoint
var buf []byte
@ -78,6 +87,9 @@ func decodeEndpoints(tags []string) []*Endpoint {
if err := json.Unmarshal(buf, &e); err == nil {
en = append(en, e)
}
// set version
ver = tag[1]
}
return en
}
@ -100,11 +112,19 @@ func encodeMetadata(md map[string]string) []string {
func decodeMetadata(tags []string) map[string]string {
md := make(map[string]string)
var ver byte
for _, tag := range tags {
if len(tag) == 0 || tag[0] != 't' {
continue
}
// check version
if ver > 0 && tag[1] != ver {
continue
}
var kv map[string]string
var buf []byte
@ -124,6 +144,9 @@ func decodeMetadata(tags []string) map[string]string {
md[k] = v
}
}
// set version
ver = tag[1]
}
return md
}