mirror of
https://github.com/go-micro/go-micro.git
synced 2025-08-10 21:52:01 +02:00
Update wrapper and examples
This commit is contained in:
@@ -8,17 +8,18 @@ import (
|
||||
)
|
||||
|
||||
type options struct {
|
||||
codecs map[string]codec.NewCodec
|
||||
broker broker.Broker
|
||||
registry registry.Registry
|
||||
transport transport.Transport
|
||||
metadata map[string]string
|
||||
name string
|
||||
address string
|
||||
advertise string
|
||||
id string
|
||||
version string
|
||||
wrappers []Wrapper
|
||||
codecs map[string]codec.NewCodec
|
||||
broker broker.Broker
|
||||
registry registry.Registry
|
||||
transport transport.Transport
|
||||
metadata map[string]string
|
||||
name string
|
||||
address string
|
||||
advertise string
|
||||
id string
|
||||
version string
|
||||
wrappers []HandlerWrapper
|
||||
subWrappers []SubscriberWrapper
|
||||
}
|
||||
|
||||
func newOptions(opt ...Option) options {
|
||||
@@ -156,8 +157,15 @@ func Metadata(md map[string]string) Option {
|
||||
}
|
||||
|
||||
// Adds a handler Wrapper to a list of options passed into the server
|
||||
func Wrap(w Wrapper) Option {
|
||||
func WrapHandler(w HandlerWrapper) Option {
|
||||
return func(o *options) {
|
||||
o.wrappers = append(o.wrappers, w)
|
||||
}
|
||||
}
|
||||
|
||||
// Adds a subscriber Wrapper to a list of options passed into the server
|
||||
func WrapSubscriber(w SubscriberWrapper) Option {
|
||||
return func(o *options) {
|
||||
o.subWrappers = append(o.subWrappers, w)
|
||||
}
|
||||
}
|
||||
|
@@ -75,7 +75,7 @@ type server struct {
|
||||
freeReq *request
|
||||
respLock sync.Mutex // protects freeResp
|
||||
freeResp *response
|
||||
wrappers []Wrapper
|
||||
wrappers []HandlerWrapper
|
||||
}
|
||||
|
||||
// Is this an exported - upper case - name?
|
||||
@@ -465,13 +465,6 @@ func (server *server) readRequestHeader(codec serverCodec) (service *service, mt
|
||||
return
|
||||
}
|
||||
|
||||
// A serverCodec implements reading of RPC requests and writing of
|
||||
// RPC responses for the server side of an RPC session.
|
||||
// The server calls ReadRequestHeader and ReadRequestBody in pairs
|
||||
// to read requests from the connection, and it calls WriteResponse to
|
||||
// write a response back. The server calls Close when finished with the
|
||||
// connection. ReadRequestBody may be called with a nil
|
||||
// argument to force the body of the request to be read and discarded.
|
||||
type serverCodec interface {
|
||||
ReadRequestHeader(*request) error
|
||||
ReadRequestBody(interface{}) error
|
||||
|
@@ -6,4 +6,8 @@ import (
|
||||
|
||||
type HandlerFunc func(ctx context.Context, req interface{}, rsp interface{}) error
|
||||
|
||||
type Wrapper func(HandlerFunc) HandlerFunc
|
||||
type SubscriberFunc func(ctx context.Context, msg interface{}) error
|
||||
|
||||
type HandlerWrapper func(HandlerFunc) HandlerFunc
|
||||
|
||||
type SubscriberWrapper func(SubscriberFunc) SubscriberFunc
|
||||
|
Reference in New Issue
Block a user