the installation of server unary interceptor

This commit is contained in:
iamqizhao
2016-04-19 15:54:30 -07:00
parent 61e92eacc3
commit c321387fd9
2 changed files with 39 additions and 2 deletions

View File

@ -99,6 +99,7 @@ type options struct {
codec Codec
cp Compressor
dc Decompressor
unaryInt UnaryServerInterceptor
maxConcurrentStreams uint32
useHandlerImpl bool // use http.Handler-based server
}
@ -140,6 +141,15 @@ func Creds(c credentials.Credentials) ServerOption {
}
}
func UnaryInterceptor(i UnaryServerInterceptor) ServerOption {
return func(o *options) {
if o.unaryInt != nil {
panic("The unary server interceptor has been set.")
}
o.unaryInt = i
}
}
// NewServer creates a gRPC server which has no service registered and has not
// started to accept requests yet.
func NewServer(opt ...ServerOption) *Server {
@ -494,7 +504,7 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport.
}
return nil
}
reply, appErr := md.Handler(srv.server, stream.Context(), df, nil)
reply, appErr := md.Handler(srv.server, stream.Context(), df, s.opts.unaryInt)
if appErr != nil {
if err, ok := appErr.(rpcError); ok {
statusCode = err.code