For the legacy
This commit is contained in:
@@ -38,7 +38,9 @@ type Message interface {
|
||||
type Request interface {
|
||||
// The service to call
|
||||
Service() string
|
||||
// The endpoint to call
|
||||
// The action to take
|
||||
Method() string
|
||||
// The endpoint to invoke
|
||||
Endpoint() string
|
||||
// The content type
|
||||
ContentType() string
|
||||
|
@@ -104,6 +104,7 @@ func (c *rpcCodec) Write(m *codec.Message, body interface{}) error {
|
||||
// set the mucp headers
|
||||
m.Header["X-Micro-Id"] = m.Id
|
||||
m.Header["X-Micro-Service"] = m.Target
|
||||
m.Header["X-Micro-Method"] = m.Method
|
||||
m.Header["X-Micro-Endpoint"] = m.Endpoint
|
||||
|
||||
// if body is bytes Frame don't encode
|
||||
@@ -154,6 +155,7 @@ func (c *rpcCodec) ReadHeader(wm *codec.Message, r codec.MessageType) error {
|
||||
// read header
|
||||
err := c.codec.ReadHeader(&me, r)
|
||||
wm.Endpoint = me.Endpoint
|
||||
wm.Method = me.Method
|
||||
wm.Id = me.Id
|
||||
wm.Error = me.Error
|
||||
|
||||
@@ -162,11 +164,16 @@ func (c *rpcCodec) ReadHeader(wm *codec.Message, r codec.MessageType) error {
|
||||
wm.Error = me.Header["X-Micro-Error"]
|
||||
}
|
||||
|
||||
// check method in header
|
||||
// check endpoint in header
|
||||
if len(me.Endpoint) == 0 {
|
||||
wm.Endpoint = me.Header["X-Micro-Endpoint"]
|
||||
}
|
||||
|
||||
// check method in header
|
||||
if len(me.Method) == 0 {
|
||||
wm.Method = me.Header["X-Micro-Method"]
|
||||
}
|
||||
|
||||
if len(me.Id) == 0 {
|
||||
wm.Id = me.Header["X-Micro-Id"]
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
type rpcRequest struct {
|
||||
service string
|
||||
method string
|
||||
endpoint string
|
||||
contentType string
|
||||
codec codec.Codec
|
||||
@@ -27,6 +28,7 @@ func newRequest(service, endpoint string, request interface{}, contentType strin
|
||||
|
||||
return &rpcRequest{
|
||||
service: service,
|
||||
method: endpoint,
|
||||
endpoint: endpoint,
|
||||
body: request,
|
||||
contentType: contentType,
|
||||
@@ -42,6 +44,10 @@ func (r *rpcRequest) Service() string {
|
||||
return r.service
|
||||
}
|
||||
|
||||
func (r *rpcRequest) Method() string {
|
||||
return r.method
|
||||
}
|
||||
|
||||
func (r *rpcRequest) Endpoint() string {
|
||||
return r.endpoint
|
||||
}
|
||||
|
@@ -53,6 +53,7 @@ func (r *rpcStream) Send(msg interface{}) error {
|
||||
req := codec.Message{
|
||||
Id: r.id,
|
||||
Target: r.request.Service(),
|
||||
Method: r.request.Method(),
|
||||
Endpoint: r.request.Endpoint(),
|
||||
Type: codec.Request,
|
||||
}
|
||||
|
Reference in New Issue
Block a user