logger.go 683 B

1234567891011121314151617181920212223242526272829
  1. package middleware
  2. import (
  3. "context"
  4. "git.sxidc.com/service-supports/fslog"
  5. "google.golang.org/grpc"
  6. )
  7. func UnaryServerFsLogInterceptor() grpc.UnaryServerInterceptor {
  8. return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
  9. resp, err := handler(ctx, req)
  10. if err != nil {
  11. fslog.Error(err)
  12. }
  13. return resp, err
  14. }
  15. }
  16. func StreamServerFsLogInterceptor() grpc.StreamServerInterceptor {
  17. return func(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
  18. err := handler(srv, stream)
  19. if err != nil {
  20. fslog.Error(err)
  21. }
  22. return err
  23. }
  24. }