add unit test, fix interceptor bug

This commit is contained in:
kevin
2020-09-29 14:30:22 +08:00
parent e7d46aa6e2
commit 33a9db85c8
6 changed files with 87 additions and 3 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"flag"
"fmt"
"log"
"os"
"sync"
"time"
@@ -50,5 +51,13 @@ func main() {
server := zrpc.MustNewServer(c, func(grpcServer *grpc.Server) {
unary.RegisterGreeterServer(grpcServer, NewGreetServer())
})
interceptor := func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
st := time.Now()
resp, err = handler(ctx, req)
log.Printf("method: %s time: %v\n", info.FullMethod, time.Since(st))
return resp, err
}
server.AddUnaryInterceptors(interceptor)
server.Start()
}