1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-24 10:07:04 +02:00

Don't strip decode because its good to be backwards compatible still

This commit is contained in:
Asim 2016-05-22 18:43:47 +01:00
parent 2708f9c04b
commit 04bc20798d

View File

@ -54,14 +54,27 @@ 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
// Old encoding was plain
if tag[1] == '=' {
buf = []byte(tag[2:])
}
// New encoding is hex
if tag[1] == '-' {
buf = decode(tag[2:])
@ -70,6 +83,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
}
@ -90,14 +106,26 @@ 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
// Old encoding was plain
if tag[1] == '=' {
buf = []byte(tag[2:])
}
// New encoding is hex
if tag[1] == '-' {
buf = decode(tag[2:])
@ -109,6 +137,9 @@ func decodeMetadata(tags []string) map[string]string {
md[k] = v
}
}
// set version
ver = tag[1]
}
return md
}
@ -123,6 +154,11 @@ func decodeVersion(tags []string) (string, bool) {
continue
}
// Old encoding was plain
if tag[1] == '=' {
return tag[2:], true
}
// New encoding is hex
if tag[1] == '-' {
return string(decode(tag[2:])), true