2015-12-02 20:56:50 +00:00
|
|
|
package server
|
|
|
|
|
2019-01-09 16:20:57 +00:00
|
|
|
import (
|
2019-11-25 16:31:43 +00:00
|
|
|
"bytes"
|
|
|
|
|
2019-01-09 16:20:57 +00:00
|
|
|
"github.com/micro/go-micro/codec"
|
2019-07-09 18:41:26 +01:00
|
|
|
"github.com/micro/go-micro/transport"
|
2019-11-25 16:31:43 +00:00
|
|
|
"github.com/micro/go-micro/util/buf"
|
2019-01-09 16:20:57 +00:00
|
|
|
)
|
|
|
|
|
2015-12-02 20:56:50 +00:00
|
|
|
type rpcRequest struct {
|
|
|
|
service string
|
2019-01-18 10:12:57 +00:00
|
|
|
method string
|
2019-01-10 21:25:31 +00:00
|
|
|
endpoint string
|
2015-12-02 20:56:50 +00:00
|
|
|
contentType string
|
2019-01-09 19:11:47 +00:00
|
|
|
socket transport.Socket
|
2019-01-09 16:20:57 +00:00
|
|
|
codec codec.Codec
|
2019-01-09 19:11:47 +00:00
|
|
|
header map[string]string
|
2019-01-09 16:20:57 +00:00
|
|
|
body []byte
|
2019-06-07 15:15:22 +01:00
|
|
|
rawBody interface{}
|
2015-12-02 21:12:09 +00:00
|
|
|
stream bool
|
2019-08-11 18:11:33 +01:00
|
|
|
first bool
|
2015-12-02 20:56:50 +00:00
|
|
|
}
|
|
|
|
|
2018-04-14 18:21:02 +01:00
|
|
|
type rpcMessage struct {
|
2015-12-02 20:56:50 +00:00
|
|
|
topic string
|
|
|
|
contentType string
|
2018-04-14 18:21:02 +01:00
|
|
|
payload interface{}
|
2019-11-25 16:31:43 +00:00
|
|
|
header map[string]string
|
|
|
|
body []byte
|
|
|
|
codec codec.NewCodec
|
2015-12-02 20:56:50 +00:00
|
|
|
}
|
|
|
|
|
2019-01-09 19:28:13 +00:00
|
|
|
func (r *rpcRequest) Codec() codec.Reader {
|
2019-01-09 16:20:57 +00:00
|
|
|
return r.codec
|
|
|
|
}
|
|
|
|
|
2015-12-02 20:56:50 +00:00
|
|
|
func (r *rpcRequest) ContentType() string {
|
|
|
|
return r.contentType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcRequest) Service() string {
|
|
|
|
return r.service
|
|
|
|
}
|
|
|
|
|
2019-01-18 10:12:57 +00:00
|
|
|
func (r *rpcRequest) Method() string {
|
|
|
|
return r.method
|
|
|
|
}
|
|
|
|
|
2019-01-10 21:25:31 +00:00
|
|
|
func (r *rpcRequest) Endpoint() string {
|
|
|
|
return r.endpoint
|
2015-12-02 20:56:50 +00:00
|
|
|
}
|
|
|
|
|
2019-01-09 19:11:47 +00:00
|
|
|
func (r *rpcRequest) Header() map[string]string {
|
|
|
|
return r.header
|
|
|
|
}
|
|
|
|
|
2019-02-04 13:13:03 +00:00
|
|
|
func (r *rpcRequest) Body() interface{} {
|
2019-06-07 15:15:22 +01:00
|
|
|
return r.rawBody
|
2019-02-04 13:13:03 +00:00
|
|
|
}
|
|
|
|
|
2019-01-09 19:11:47 +00:00
|
|
|
func (r *rpcRequest) Read() ([]byte, error) {
|
|
|
|
// got a body
|
2019-08-11 18:11:33 +01:00
|
|
|
if r.first {
|
2019-01-09 19:11:47 +00:00
|
|
|
b := r.body
|
2019-08-11 18:11:33 +01:00
|
|
|
r.first = false
|
2019-01-09 19:11:47 +00:00
|
|
|
return b, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var msg transport.Message
|
|
|
|
err := r.socket.Recv(&msg)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
r.header = msg.Header
|
|
|
|
|
|
|
|
return msg.Body, nil
|
2015-12-02 20:56:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcRequest) Stream() bool {
|
|
|
|
return r.stream
|
|
|
|
}
|
|
|
|
|
2018-04-14 18:21:02 +01:00
|
|
|
func (r *rpcMessage) ContentType() string {
|
2015-12-02 20:56:50 +00:00
|
|
|
return r.contentType
|
|
|
|
}
|
|
|
|
|
2018-04-14 18:21:02 +01:00
|
|
|
func (r *rpcMessage) Topic() string {
|
2015-12-02 20:56:50 +00:00
|
|
|
return r.topic
|
|
|
|
}
|
|
|
|
|
2018-04-14 18:21:02 +01:00
|
|
|
func (r *rpcMessage) Payload() interface{} {
|
|
|
|
return r.payload
|
2015-12-02 20:56:50 +00:00
|
|
|
}
|
2019-11-25 16:31:43 +00:00
|
|
|
|
|
|
|
func (r *rpcMessage) Header() map[string]string {
|
|
|
|
return r.header
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcMessage) Body() []byte {
|
|
|
|
return r.body
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcMessage) Codec() codec.Reader {
|
|
|
|
b := buf.New(bytes.NewBuffer(r.body))
|
|
|
|
return r.codec(b)
|
|
|
|
}
|