2015-12-03 04:02:14 +03:00
|
|
|
package client
|
|
|
|
|
2015-11-26 23:36:42 +03:00
|
|
|
/*
|
|
|
|
Wrapper is a type of middleware for the go-micro client. It allows
|
|
|
|
the client to be "wrapped" so that requests and responses can be intercepted
|
|
|
|
to perform extra requirements such as auth, tracing, monitoring, logging, etc.
|
|
|
|
|
|
|
|
Example usage:
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"github.com/micro/go-micro/client"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
type LogWrapper struct {
|
|
|
|
client.Client
|
|
|
|
}
|
|
|
|
|
2015-12-08 22:37:27 +03:00
|
|
|
func (l *LogWrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error {
|
2015-11-26 23:36:42 +03:00
|
|
|
log.Println("Making request to service " + req.Service() + " method " + req.Method())
|
|
|
|
return w.Client.Call(ctx, req, rsp)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Wrapper(c client.Client) client.Client {
|
|
|
|
return &LogWrapper{c}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
c := client.NewClient(client.Wrap(Wrapper))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2016-11-07 20:49:35 +03:00
|
|
|
import (
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CallFunc represents the individual call func
|
|
|
|
type CallFunc func(ctx context.Context, address string, req Request, rsp interface{}, opts CallOptions) error
|
|
|
|
|
2016-11-07 20:58:34 +03:00
|
|
|
// CallWrapper is a low level wrapper for the CallFunc
|
|
|
|
type CallWrapper func(CallFunc) CallFunc
|
2016-11-07 20:49:35 +03:00
|
|
|
|
2015-11-26 23:36:42 +03:00
|
|
|
// Wrapper wraps a client and returns a client
|
|
|
|
type Wrapper func(Client) Client
|
2015-12-18 04:01:59 +03:00
|
|
|
|
|
|
|
// StreamWrapper wraps a Stream and returns the equivalent
|
|
|
|
type StreamWrapper func(Streamer) Streamer
|