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.
44 lines
1.4 KiB
44 lines
1.4 KiB
package config |
|
|
|
import ( |
|
"google.golang.org/grpc" |
|
"google.golang.org/grpc/keepalive" |
|
"sonet/pkg/utils/conver" |
|
) |
|
|
|
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 |
|
}
|
|
|