rename method to endpoint
This commit is contained in:
@@ -106,14 +106,14 @@ func (c *rpcCodec) ReadHeader(r *codec.Message, t codec.MessageType) error {
|
||||
|
||||
// set some internal things
|
||||
m.Target = m.Header["X-Micro-Service"]
|
||||
m.Method = m.Header["X-Micro-Method"]
|
||||
m.Endpoint = m.Header["X-Micro-Endpoint"]
|
||||
m.Id = m.Header["X-Micro-Id"]
|
||||
|
||||
// read header via codec
|
||||
err := c.codec.ReadHeader(&m, codec.Request)
|
||||
|
||||
// set the method/id
|
||||
r.Method = m.Method
|
||||
r.Endpoint = m.Endpoint
|
||||
r.Id = m.Id
|
||||
|
||||
return err
|
||||
@@ -128,15 +128,15 @@ func (c *rpcCodec) Write(r *codec.Message, b interface{}) error {
|
||||
|
||||
// create a new message
|
||||
m := &codec.Message{
|
||||
Method: r.Method,
|
||||
Id: r.Id,
|
||||
Error: r.Error,
|
||||
Type: r.Type,
|
||||
Endpoint: r.Endpoint,
|
||||
Id: r.Id,
|
||||
Error: r.Error,
|
||||
Type: r.Type,
|
||||
Header: map[string]string{
|
||||
"X-Micro-Id": r.Id,
|
||||
"X-Micro-Method": r.Method,
|
||||
"X-Micro-Error": r.Error,
|
||||
"Content-Type": c.req.Header["Content-Type"],
|
||||
"X-Micro-Id": r.Id,
|
||||
"X-Micro-Endpoint": r.Endpoint,
|
||||
"X-Micro-Error": r.Error,
|
||||
"Content-Type": c.req.Header["Content-Type"],
|
||||
},
|
||||
}
|
||||
|
||||
|
@@ -48,9 +48,9 @@ func TestCodecWriteError(t *testing.T) {
|
||||
}
|
||||
|
||||
err := c.Write(&codec.Message{
|
||||
Method: "Service.Method",
|
||||
Id: "0",
|
||||
Error: "",
|
||||
Endpoint: "Service.Endpoint",
|
||||
Id: "0",
|
||||
Error: "",
|
||||
}, "body")
|
||||
|
||||
if err != nil {
|
||||
|
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
type rpcRequest struct {
|
||||
service string
|
||||
method string
|
||||
endpoint string
|
||||
contentType string
|
||||
socket transport.Socket
|
||||
codec codec.Codec
|
||||
@@ -34,8 +34,8 @@ func (r *rpcRequest) Service() string {
|
||||
return r.service
|
||||
}
|
||||
|
||||
func (r *rpcRequest) Method() string {
|
||||
return r.method
|
||||
func (r *rpcRequest) Endpoint() string {
|
||||
return r.endpoint
|
||||
}
|
||||
|
||||
func (r *rpcRequest) Header() map[string]string {
|
||||
|
@@ -171,7 +171,7 @@ func (router *router) sendResponse(sending sync.Locker, req *request, reply inte
|
||||
resp.msg = msg
|
||||
|
||||
// Encode the response header
|
||||
resp.msg.Method = req.msg.Method
|
||||
resp.msg.Endpoint = req.msg.Endpoint
|
||||
if errmsg != "" {
|
||||
resp.msg.Error = errmsg
|
||||
reply = invalidRequest
|
||||
@@ -191,7 +191,7 @@ func (s *service) call(ctx context.Context, router *router, sending *sync.Mutex,
|
||||
r := &rpcRequest{
|
||||
service: req.msg.Target,
|
||||
contentType: req.msg.Header["Content-Type"],
|
||||
method: req.msg.Method,
|
||||
endpoint: req.msg.Endpoint,
|
||||
body: req.msg.Body,
|
||||
}
|
||||
|
||||
@@ -379,9 +379,9 @@ func (router *router) readHeader(cc codec.Reader) (service *service, mtype *meth
|
||||
// we can still recover and move on to the next request.
|
||||
keepReading = true
|
||||
|
||||
serviceMethod := strings.Split(req.msg.Method, ".")
|
||||
serviceMethod := strings.Split(req.msg.Endpoint, ".")
|
||||
if len(serviceMethod) != 2 {
|
||||
err = errors.New("rpc: service/method request ill-formed: " + req.msg.Method)
|
||||
err = errors.New("rpc: service/method request ill-formed: " + req.msg.Endpoint)
|
||||
return
|
||||
}
|
||||
// Look up the request.
|
||||
@@ -389,12 +389,12 @@ func (router *router) readHeader(cc codec.Reader) (service *service, mtype *meth
|
||||
service = router.serviceMap[serviceMethod[0]]
|
||||
router.mu.Unlock()
|
||||
if service == nil {
|
||||
err = errors.New("rpc: can't find service " + req.msg.Method)
|
||||
err = errors.New("rpc: can't find service " + req.msg.Endpoint)
|
||||
return
|
||||
}
|
||||
mtype = service.method[serviceMethod[1]]
|
||||
if mtype == nil {
|
||||
err = errors.New("rpc: can't find method " + req.msg.Method)
|
||||
err = errors.New("rpc: can't find method " + req.msg.Endpoint)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@@ -115,7 +115,7 @@ func (s *rpcServer) ServeConn(sock transport.Socket) {
|
||||
// internal request
|
||||
request := &rpcRequest{
|
||||
service: msg.Header["X-Micro-Service"],
|
||||
method: msg.Header["X-Micro-Method"],
|
||||
endpoint: msg.Header["X-Micro-Endpoint"],
|
||||
contentType: ct,
|
||||
codec: codec,
|
||||
header: msg.Header,
|
||||
|
@@ -31,9 +31,9 @@ func (r *rpcStream) Send(msg interface{}) error {
|
||||
defer r.Unlock()
|
||||
|
||||
resp := codec.Message{
|
||||
Method: r.request.Method(),
|
||||
Id: r.id,
|
||||
Type: codec.Response,
|
||||
Endpoint: r.request.Endpoint(),
|
||||
Id: r.id,
|
||||
Type: codec.Response,
|
||||
}
|
||||
|
||||
return r.codec.Write(&resp, msg)
|
||||
|
@@ -45,8 +45,8 @@ type Message interface {
|
||||
type Request interface {
|
||||
// Service name requested
|
||||
Service() string
|
||||
// Method name requested
|
||||
Method() string
|
||||
// Endpoint name requested
|
||||
Endpoint() string
|
||||
// Content type provided
|
||||
ContentType() string
|
||||
// Header of the request
|
||||
@@ -83,7 +83,7 @@ type Stream interface {
|
||||
}
|
||||
|
||||
// Handler interface represents a request handler. It's generated
|
||||
// by passing any type of public concrete object with methods into server.NewHandler.
|
||||
// by passing any type of public concrete object with endpoints into server.NewHandler.
|
||||
// Most will pass in a struct.
|
||||
//
|
||||
// Example:
|
||||
@@ -102,7 +102,7 @@ type Handler interface {
|
||||
}
|
||||
|
||||
// Subscriber interface represents a subscription to a given topic using
|
||||
// a specific subscriber function or object with methods.
|
||||
// a specific subscriber function or object with endpoints.
|
||||
type Subscriber interface {
|
||||
Topic() string
|
||||
Subscriber() interface{}
|
||||
@@ -151,7 +151,7 @@ func NewSubscriber(topic string, h interface{}, opts ...SubscriberOption) Subscr
|
||||
|
||||
// NewHandler creates a new handler interface using the default server
|
||||
// Handlers are required to be a public object with public
|
||||
// methods. Call to a service method such as Foo.Bar expects
|
||||
// endpoints. Call to a service endpoint such as Foo.Bar expects
|
||||
// the type:
|
||||
//
|
||||
// type Foo struct {}
|
||||
|
Reference in New Issue
Block a user