2015-12-02 23:56:50 +03:00
|
|
|
package server
|
|
|
|
|
2019-01-09 19:20:57 +03:00
|
|
|
import (
|
|
|
|
"github.com/micro/go-micro/codec"
|
2019-01-09 22:11:47 +03:00
|
|
|
"github.com/micro/go-micro/transport"
|
2019-01-09 19:20:57 +03:00
|
|
|
)
|
|
|
|
|
2015-12-02 23:56:50 +03:00
|
|
|
type rpcRequest struct {
|
|
|
|
service string
|
|
|
|
method string
|
|
|
|
contentType string
|
2019-01-09 22:11:47 +03:00
|
|
|
socket transport.Socket
|
2019-01-09 19:20:57 +03:00
|
|
|
codec codec.Codec
|
2019-01-09 22:11:47 +03:00
|
|
|
header map[string]string
|
2019-01-09 19:20:57 +03:00
|
|
|
body []byte
|
2015-12-03 00:12:09 +03:00
|
|
|
stream bool
|
2015-12-02 23:56:50 +03:00
|
|
|
}
|
|
|
|
|
2018-04-14 20:21:02 +03:00
|
|
|
type rpcMessage struct {
|
2015-12-02 23:56:50 +03:00
|
|
|
topic string
|
|
|
|
contentType string
|
2018-04-14 20:21:02 +03:00
|
|
|
payload interface{}
|
2015-12-02 23:56:50 +03:00
|
|
|
}
|
|
|
|
|
2019-01-09 22:28:13 +03:00
|
|
|
func (r *rpcRequest) Codec() codec.Reader {
|
2019-01-09 19:20:57 +03:00
|
|
|
return r.codec
|
|
|
|
}
|
|
|
|
|
2015-12-02 23:56:50 +03:00
|
|
|
func (r *rpcRequest) ContentType() string {
|
|
|
|
return r.contentType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcRequest) Service() string {
|
|
|
|
return r.service
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcRequest) Method() string {
|
|
|
|
return r.method
|
|
|
|
}
|
|
|
|
|
2019-01-09 22:11:47 +03:00
|
|
|
func (r *rpcRequest) Header() map[string]string {
|
|
|
|
return r.header
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcRequest) Read() ([]byte, error) {
|
|
|
|
// got a body
|
|
|
|
if r.body != nil {
|
|
|
|
b := r.body
|
|
|
|
r.body = nil
|
|
|
|
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 23:56:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcRequest) Stream() bool {
|
|
|
|
return r.stream
|
|
|
|
}
|
|
|
|
|
2018-04-14 20:21:02 +03:00
|
|
|
func (r *rpcMessage) ContentType() string {
|
2015-12-02 23:56:50 +03:00
|
|
|
return r.contentType
|
|
|
|
}
|
|
|
|
|
2018-04-14 20:21:02 +03:00
|
|
|
func (r *rpcMessage) Topic() string {
|
2015-12-02 23:56:50 +03:00
|
|
|
return r.topic
|
|
|
|
}
|
|
|
|
|
2018-04-14 20:21:02 +03:00
|
|
|
func (r *rpcMessage) Payload() interface{} {
|
|
|
|
return r.payload
|
2015-12-02 23:56:50 +03:00
|
|
|
}
|