github.com/moqsien/xraycore@v1.8.5/infra/conf/grpc.go (about)

     1  package conf
     2  
     3  import (
     4  	"github.com/moqsien/xraycore/transport/internet/grpc"
     5  	"google.golang.org/protobuf/proto"
     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  	UserAgent           string `json:"user_agent"`
    16  }
    17  
    18  func (g *GRPCConfig) Build() (proto.Message, error) {
    19  	if g.IdleTimeout <= 0 {
    20  		g.IdleTimeout = 0
    21  	}
    22  	if g.HealthCheckTimeout <= 0 {
    23  		g.HealthCheckTimeout = 0
    24  	}
    25  	if g.InitialWindowsSize < 0 {
    26  		// default window size of gRPC-go
    27  		g.InitialWindowsSize = 0
    28  	}
    29  
    30  	return &grpc.Config{
    31  		ServiceName:         g.ServiceName,
    32  		MultiMode:           g.MultiMode,
    33  		IdleTimeout:         g.IdleTimeout,
    34  		HealthCheckTimeout:  g.HealthCheckTimeout,
    35  		PermitWithoutStream: g.PermitWithoutStream,
    36  		InitialWindowsSize:  g.InitialWindowsSize,
    37  		UserAgent:           g.UserAgent,
    38  	}, nil
    39  }