github.com/xraypb/xray-core@v1.6.6/infra/conf/grpc.go (about)

     1  package conf
     2  
     3  import (
     4  	"github.com/golang/protobuf/proto"
     5  	"github.com/xraypb/xray-core/transport/internet/grpc"
     6  )
     7  
     8  type GRPCConfig struct {
     9  	ServiceName         string `json:"serviceName" `
    10  	MultiMode           bool   `json:"multiMode"`
    11  	IdleTimeout         int32  `json:"idle_timeout"`
    12  	HealthCheckTimeout  int32  `json:"health_check_timeout"`
    13  	PermitWithoutStream bool   `json:"permit_without_stream"`
    14  	InitialWindowsSize  int32  `json:"initial_windows_size"`
    15  }
    16  
    17  func (g *GRPCConfig) Build() (proto.Message, error) {
    18  	if g.IdleTimeout <= 0 {
    19  		g.IdleTimeout = 0
    20  	}
    21  	if g.HealthCheckTimeout <= 0 {
    22  		g.HealthCheckTimeout = 0
    23  	}
    24  	if g.InitialWindowsSize < 0 {
    25  		// default window size of gRPC-go
    26  		g.InitialWindowsSize = 0
    27  	}
    28  
    29  	return &grpc.Config{
    30  		ServiceName:         g.ServiceName,
    31  		MultiMode:           g.MultiMode,
    32  		IdleTimeout:         g.IdleTimeout,
    33  		HealthCheckTimeout:  g.HealthCheckTimeout,
    34  		PermitWithoutStream: g.PermitWithoutStream,
    35  		InitialWindowsSize:  g.InitialWindowsSize,
    36  	}, nil
    37  }