Account for old target

This commit is contained in:
Asim Aslam 2019-01-18 10:43:41 +00:00
parent f41be53ff8
commit 9bd32645be

View File

@ -68,29 +68,38 @@ func (rwc *readWriteCloser) Close() error {
// setupProtocol sets up the old protocol // setupProtocol sets up the old protocol
func setupProtocol(msg *transport.Message) codec.NewCodec { func setupProtocol(msg *transport.Message) codec.NewCodec {
// if the protocol exists do nothing service := msg.Header["X-Micro-Service"]
if len(msg.Header["X-Micro-Protocol"]) > 0 { method := msg.Header["X-Micro-Method"]
endpoint := msg.Header["X-Micro-Endpoint"]
protocol := msg.Header["X-Micro-Protocol"]
target := msg.Header["X-Micro-Target"]
// if the protocol exists (mucp) do nothing
if len(protocol) > 0 {
return nil return nil
} }
// if 0.17 - 0.21 // if no service/method/endpoint then it's the old protocol
if len(msg.Header["X-Micro-Service"]) > 0 { if len(service) == 0 && len(method) == 0 && len(endpoint) == 0 {
// set method to endpoint return defaultCodecs[msg.Header["Content-Type"]]
if len(msg.Header["X-Micro-Method"]) == 0 {
msg.Header["X-Micro-Method"] = msg.Header["X-Micro-Endpoint"]
}
// set endpoint to method
if len(msg.Header["X-Micro-Endpoint"]) == 0 {
msg.Header["X-Micro-Endpoint"] = msg.Header["X-Micro-Method"]
}
// done
return nil
} }
// old ways // old target method specified
return defaultCodecs[msg.Header["Content-Type"]] if len(target) > 0 {
return defaultCodecs[msg.Header["Content-Type"]]
}
// no method then set to endpoint
if len(method) == 0 {
msg.Header["X-Micro-Method"] = method
}
// no endpoint then set to method
if len(endpoint) == 0 {
msg.Header["X-Micro-Endpoint"] = method
}
return nil
} }
func newRpcCodec(req *transport.Message, socket transport.Socket, c codec.NewCodec) codec.Codec { func newRpcCodec(req *transport.Message, socket transport.Socket, c codec.NewCodec) codec.Codec {