package config import ( "sig-pub/pkg/utils/conver" "google.golang.org/grpc" "google.golang.org/grpc/keepalive" ) func GetGrpcOptions(c GrpcConfig, customOpts ...grpc.ServerOption) (opts []grpc.ServerOption) { if c.MaxSendMsgSize != "" { opts = append(opts, grpc.MaxSendMsgSize(conver.MustParseDataUnitInt(c.MaxSendMsgSize))) } if c.MaxRecvMsgSize != "" { opts = append(opts, grpc.MaxSendMsgSize(conver.MustParseDataUnitInt(c.MaxRecvMsgSize))) } if c.ReadBufferSize != "" { opts = append(opts, grpc.MaxSendMsgSize(conver.MustParseDataUnitInt(c.ReadBufferSize))) } if c.WriteBufferSize != "" { opts = append(opts, grpc.MaxSendMsgSize(conver.MustParseDataUnitInt(c.WriteBufferSize))) } // grpc server keepalive keep := keepalive.ServerParameters{} if c.keepalive.IdleTimeout != "" { keep.MaxConnectionIdle = conver.MustParseDuration(c.keepalive.IdleTimeout) } if c.keepalive.ForceCloseWait != "" { keep.MaxConnectionAgeGrace = conver.MustParseDuration(c.keepalive.ForceCloseWait) } if c.keepalive.KeepAliveInterval != "" { keep.Time = conver.MustParseDuration(c.keepalive.KeepAliveInterval) } if c.keepalive.KeepAliveTimeout != "" { keep.Timeout = conver.MustParseDuration(c.keepalive.KeepAliveTimeout) } if c.keepalive.MaxLifeTime != "" { keep.MaxConnectionAge = conver.MustParseDuration(c.keepalive.MaxLifeTime) } opts = append(opts, grpc.KeepaliveParams(keep)) opts = append(opts, customOpts...) return }