Rename to hdlrWrappers for symmetry sake

This commit is contained in:
Asim 2015-12-02 21:12:09 +00:00
parent 96d7975052
commit 5e364693ee
6 changed files with 34 additions and 36 deletions

View File

@ -8,18 +8,18 @@ import (
) )
type options struct { type options struct {
codecs map[string]codec.NewCodec codecs map[string]codec.NewCodec
broker broker.Broker broker broker.Broker
registry registry.Registry registry registry.Registry
transport transport.Transport transport transport.Transport
metadata map[string]string metadata map[string]string
name string name string
address string address string
advertise string advertise string
id string id string
version string version string
wrappers []HandlerWrapper hdlrWrappers []HandlerWrapper
subWrappers []SubscriberWrapper subWrappers []SubscriberWrapper
} }
func newOptions(opt ...Option) options { func newOptions(opt ...Option) options {
@ -159,7 +159,7 @@ func Metadata(md map[string]string) Option {
// Adds a handler Wrapper to a list of options passed into the server // Adds a handler Wrapper to a list of options passed into the server
func WrapHandler(w HandlerWrapper) Option { func WrapHandler(w HandlerWrapper) Option {
return func(o *options) { return func(o *options) {
o.wrappers = append(o.wrappers, w) o.hdlrWrappers = append(o.hdlrWrappers, w)
} }
} }

View File

@ -5,7 +5,7 @@ type rpcRequest struct {
method string method string
contentType string contentType string
request interface{} request interface{}
stream bool stream bool
} }
type rpcPublication struct { type rpcPublication struct {

View File

@ -32,9 +32,9 @@ func newRpcServer(opts ...Option) Server {
return &rpcServer{ return &rpcServer{
opts: options, opts: options,
rpc: &server{ rpc: &server{
name: options.name, name: options.name,
serviceMap: make(map[string]*service), serviceMap: make(map[string]*service),
wrappers: options.wrappers, hdlrWrappers: options.hdlrWrappers,
}, },
handlers: make(map[string]Handler), handlers: make(map[string]Handler),
subscribers: make(map[*subscriber][]broker.Subscriber), subscribers: make(map[*subscriber][]broker.Subscriber),

View File

@ -69,14 +69,14 @@ type response struct {
// server represents an RPC Server. // server represents an RPC Server.
type server struct { type server struct {
name string name string
mu sync.Mutex // protects the serviceMap mu sync.Mutex // protects the serviceMap
serviceMap map[string]*service serviceMap map[string]*service
reqLock sync.Mutex // protects freeReq reqLock sync.Mutex // protects freeReq
freeReq *request freeReq *request
respLock sync.Mutex // protects freeResp respLock sync.Mutex // protects freeResp
freeResp *response freeResp *response
wrappers []HandlerWrapper hdlrWrappers []HandlerWrapper
} }
// Is this an exported - upper case - name? // Is this an exported - upper case - name?
@ -238,10 +238,10 @@ func (s *service) call(ctx context.Context, server *server, sending *sync.Mutex,
var returnValues []reflect.Value var returnValues []reflect.Value
r := &rpcRequest{ r := &rpcRequest{
service: s.name, service: s.name,
contentType: ct, contentType: ct,
method: req.ServiceMethod, method: req.ServiceMethod,
request: argv.Interface(), request: argv.Interface(),
} }
if !mtype.stream { if !mtype.stream {
@ -256,8 +256,8 @@ func (s *service) call(ctx context.Context, server *server, sending *sync.Mutex,
return nil return nil
} }
for i := len(server.wrappers); i > 0; i-- { for i := len(server.hdlrWrappers); i > 0; i-- {
fn = server.wrappers[i-1](fn) fn = server.hdlrWrappers[i-1](fn)
} }
errmsg := "" errmsg := ""
@ -266,7 +266,6 @@ func (s *service) call(ctx context.Context, server *server, sending *sync.Mutex,
errmsg = err.Error() errmsg = err.Error()
} }
server.sendResponse(sending, req, replyv.Interface(), codec, errmsg, true) server.sendResponse(sending, req, replyv.Interface(), codec, errmsg, true)
server.freeRequest(req) server.freeRequest(req)
return return
@ -323,8 +322,8 @@ func (s *service) call(ctx context.Context, server *server, sending *sync.Mutex,
return nil return nil
} }
for i := len(server.wrappers); i > 0; i-- { for i := len(server.hdlrWrappers); i > 0; i-- {
fn = server.wrappers[i-1](fn) fn = server.hdlrWrappers[i-1](fn)
} }
// client.Stream request // client.Stream request

View File

@ -31,7 +31,6 @@ type Server interface {
Stop() error Stop() error
} }
type Publication interface { type Publication interface {
Topic() string Topic() string
Message() interface{} Message() interface{}

View File

@ -220,9 +220,9 @@ func (s *rpcServer) createSubHandler(sb *subscriber, opts options) broker.Handle
} }
go fn(ctx, &rpcPublication{ go fn(ctx, &rpcPublication{
topic: sb.topic, topic: sb.topic,
contentType: ct, contentType: ct,
message: req.Interface(), message: req.Interface(),
}) })
} }
} }