You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

42 lines
1.3 KiB

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.MaxRecvMsgSize(conver.MustParseDataUnitInt(c.MaxRecvMsgSize)))
}
if c.ReadBufferSize != "" {
opts = append(opts, grpc.ReadBufferSize(conver.MustParseDataUnitInt(c.ReadBufferSize)))
}
if c.WriteBufferSize != "" {
opts = append(opts, grpc.WriteBufferSize(conver.MustParseDataUnitInt(c.WriteBufferSize)))
}
// grpc server keepalive
keep := keepalive.ServerParameters{}
if c.keepalive.IdleTimeout != "" {
keep.MaxConnectionIdle = conver.MustParseDuration(c.keepalive.IdleTimeout)
}
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
}