|
| 1 | +package options |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/spf13/pflag" |
| 5 | + "math" |
| 6 | + "time" |
| 7 | +) |
| 8 | + |
| 9 | +type GRPCServerOptions struct { |
| 10 | + TLSCertFile string |
| 11 | + TLSKeyFile string |
| 12 | + ClientCAFile string |
| 13 | + ServerBindPort string |
| 14 | + MaxConcurrentStreams uint32 |
| 15 | + MaxReceiveMessageSize int |
| 16 | + MaxSendMessageSize int |
| 17 | + ConnectionTimeout time.Duration |
| 18 | + WriteBufferSize int |
| 19 | + ReadBufferSize int |
| 20 | + MaxConnectionAge time.Duration |
| 21 | + ClientMinPingInterval time.Duration |
| 22 | + ServerPingInterval time.Duration |
| 23 | + ServerPingTimeout time.Duration |
| 24 | + PermitPingWithoutStream bool |
| 25 | +} |
| 26 | + |
| 27 | +func NewGRPCServerOptions() *GRPCServerOptions { |
| 28 | + return &GRPCServerOptions{ |
| 29 | + ServerBindPort: "8090", |
| 30 | + MaxConcurrentStreams: math.MaxUint32, |
| 31 | + MaxReceiveMessageSize: 1024 * 1024 * 4, |
| 32 | + MaxSendMessageSize: math.MaxInt32, |
| 33 | + ConnectionTimeout: 120 * time.Second, |
| 34 | + MaxConnectionAge: time.Duration(math.MaxInt64), |
| 35 | + ClientMinPingInterval: 5 * time.Second, |
| 36 | + ServerPingInterval: 30 * time.Second, |
| 37 | + ServerPingTimeout: 10 * time.Second, |
| 38 | + WriteBufferSize: 32 * 1024, |
| 39 | + ReadBufferSize: 32 * 1024, |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +func (o *GRPCServerOptions) AddFlags(flags *pflag.FlagSet) { |
| 44 | + flags.StringVar(&o.ServerBindPort, "grpc-server-bindport", o.ServerBindPort, "gPRC server bind port") |
| 45 | + flags.Uint32Var(&o.MaxConcurrentStreams, "grpc-max-concurrent-streams", o.MaxConcurrentStreams, "gPRC max concurrent streams") |
| 46 | + flags.IntVar(&o.MaxReceiveMessageSize, "grpc-max-receive-message-size", o.MaxReceiveMessageSize, "gPRC max receive message size") |
| 47 | + flags.IntVar(&o.MaxSendMessageSize, "grpc-max-send-message-size", o.MaxSendMessageSize, "gPRC max send message size") |
| 48 | + flags.DurationVar(&o.ConnectionTimeout, "grpc-connection-timeout", o.ConnectionTimeout, "gPRC connection timeout") |
| 49 | + flags.DurationVar(&o.MaxConnectionAge, "grpc-max-connection-age", o.MaxConnectionAge, "A duration for the maximum amount of time connection may exist before closing") |
| 50 | + flags.DurationVar(&o.ClientMinPingInterval, "grpc-client-min-ping-interval", o.ClientMinPingInterval, "Server will terminate the connection if the client pings more than once within this duration") |
| 51 | + flags.DurationVar(&o.ServerPingInterval, "grpc-server-ping-interval", o.ServerPingInterval, "Duration after which the server pings the client if no activity is detected") |
| 52 | + flags.DurationVar(&o.ServerPingTimeout, "grpc-server-ping-timeout", o.ServerPingTimeout, "Duration the client waits for a response after sending a keepalive ping") |
| 53 | + flags.BoolVar(&o.PermitPingWithoutStream, "permit-ping-without-stream", o.PermitPingWithoutStream, "Allow keepalive pings even when there are no active streams") |
| 54 | + flags.IntVar(&o.WriteBufferSize, "grpc-write-buffer-size", o.WriteBufferSize, "gPRC write buffer size") |
| 55 | + flags.IntVar(&o.ReadBufferSize, "grpc-read-buffer-size", o.ReadBufferSize, "gPRC read buffer size") |
| 56 | + flags.StringVar(&o.TLSCertFile, "grpc-tls-cert-file", "", "The path to the tls.crt file") |
| 57 | + flags.StringVar(&o.TLSKeyFile, "grpc-tls-key-file", "", "The path to the tls.key file") |
| 58 | + flags.StringVar(&o.ClientCAFile, "grpc-client-ca-file", "", "The path to the client ca file, must specify if using mtls authentication type") |
| 59 | +} |
0 commit comments