From 5c03e77a3deea80df200313e2d4b10c47a0647ce Mon Sep 17 00:00:00 2001 From: anti-duhring Date: Mon, 30 Dec 2024 11:17:51 -0300 Subject: [PATCH] feat: adding param MaxReceiveMessageSize on NewServer --- pkg/grpc/server.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/grpc/server.go b/pkg/grpc/server.go index 1c34ff2..7c4ac45 100644 --- a/pkg/grpc/server.go +++ b/pkg/grpc/server.go @@ -18,8 +18,9 @@ type BareServer struct { type NewServerParams struct { fx.In - Logger *zerolog.Logger - Interceptors []grpc.UnaryServerInterceptor `group:"interceptors"` + Logger *zerolog.Logger + Interceptors []grpc.UnaryServerInterceptor `group:"interceptors"` + MaxReceiveMessageSize *int } func NewServer(params NewServerParams) *BareServer { @@ -32,6 +33,12 @@ func NewServer(params NewServerParams) *BareServer { append(params.Interceptors, grpcLoggerInterceptor(params.Logger))..., ) + // default max message size is 4MB + maxReceiveMessageSize := 4 * 1024 * 1024 + if params.MaxReceiveMessageSize != nil { + maxReceiveMessageSize = *params.MaxReceiveMessageSize + } + sv := grpc.NewServer( grpc.StatsHandler( otelgrpc.NewServerHandler(), @@ -39,6 +46,7 @@ func NewServer(params NewServerParams) *BareServer { grpc.ChainUnaryInterceptor( params.Interceptors..., ), + grpc.MaxRecvMsgSize(maxReceiveMessageSize), ) grpcServer.Server = sv