mirror of
https://github.com/3ybactuk/marketplace-go-service-project.git
synced 2025-10-30 05:53:45 +03:00
25 lines
727 B
Go
25 lines
727 B
Go
package mw
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/protobuf/encoding/protojson"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
func Logging(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) {
|
|
raw, _ := protojson.Marshal((req).(proto.Message))
|
|
log.Debug().Msgf("request: method: %v, req: %s", info.FullMethod, string(raw))
|
|
|
|
if resp, err = handler(ctx, req); err != nil {
|
|
log.Debug().Msgf("response: method: %v, err: %s", info.FullMethod, err.Error())
|
|
return
|
|
}
|
|
rawResp, _ := protojson.Marshal((resp).(proto.Message))
|
|
log.Debug().Msgf("response: method: %v, resp: %s", info.FullMethod, string(rawResp))
|
|
|
|
return
|
|
}
|