dubbo.apache.org/dubbo-go/v3@v3.1.1/config/protocol_config.go (about)

     1  /*
     2   * Licensed to the Apache Software Foundation (ASF) under one or more
     3   * contributor license agreements.  See the NOTICE file distributed with
     4   * this work for additional information regarding copyright ownership.
     5   * The ASF licenses this file to You under the Apache License, Version 2.0
     6   * (the "License"); you may not use this file except in compliance with
     7   * the License.  You may obtain a copy of the License at
     8   *
     9   *     http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  
    18  package config
    19  
    20  import (
    21  	"github.com/creasty/defaults"
    22  )
    23  
    24  import (
    25  	"dubbo.apache.org/dubbo-go/v3/common/constant"
    26  )
    27  
    28  // ProtocolConfig is protocol configuration
    29  type ProtocolConfig struct {
    30  	Name   string      `default:"dubbo" validate:"required" yaml:"name" json:"name,omitempty" property:"name"`
    31  	Ip     string      `yaml:"ip"  json:"ip,omitempty" property:"ip"`
    32  	Port   string      `default:"20000" yaml:"port" json:"port,omitempty" property:"port"`
    33  	Params interface{} `yaml:"params" json:"params,omitempty" property:"params"`
    34  
    35  	// MaxServerSendMsgSize max size of server send message, 1mb=1000kb=1000000b 1mib=1024kb=1048576b.
    36  	// more detail to see https://pkg.go.dev/github.com/dustin/go-humanize#pkg-constants
    37  	MaxServerSendMsgSize string `yaml:"max-server-send-msg-size" json:"max-server-send-msg-size,omitempty"`
    38  	// MaxServerRecvMsgSize max size of server receive message
    39  	MaxServerRecvMsgSize string `default:"4mib" yaml:"max-server-recv-msg-size" json:"max-server-recv-msg-size,omitempty"`
    40  }
    41  
    42  // Prefix dubbo.config-center
    43  func (ProtocolConfig) Prefix() string {
    44  	return constant.ConfigCenterPrefix
    45  }
    46  
    47  func GetProtocolsInstance() map[string]*ProtocolConfig {
    48  	return make(map[string]*ProtocolConfig, 1)
    49  }
    50  
    51  func (p *ProtocolConfig) Init() error {
    52  	if err := defaults.Set(p); err != nil {
    53  		return err
    54  	}
    55  	return verify(p)
    56  }
    57  
    58  func NewProtocolConfigBuilder() *ProtocolConfigBuilder {
    59  	return &ProtocolConfigBuilder{protocolConfig: &ProtocolConfig{}}
    60  }
    61  
    62  type ProtocolConfigBuilder struct {
    63  	protocolConfig *ProtocolConfig
    64  }
    65  
    66  func (pcb *ProtocolConfigBuilder) SetName(name string) *ProtocolConfigBuilder {
    67  	pcb.protocolConfig.Name = name
    68  	return pcb
    69  }
    70  
    71  func (pcb *ProtocolConfigBuilder) SetIp(ip string) *ProtocolConfigBuilder {
    72  	pcb.protocolConfig.Ip = ip
    73  	return pcb
    74  }
    75  
    76  func (pcb *ProtocolConfigBuilder) SetPort(port string) *ProtocolConfigBuilder {
    77  	pcb.protocolConfig.Port = port
    78  	return pcb
    79  }
    80  
    81  func (pcb *ProtocolConfigBuilder) SetParams(params interface{}) *ProtocolConfigBuilder {
    82  	pcb.protocolConfig.Params = params
    83  	return pcb
    84  }
    85  
    86  func (pcb *ProtocolConfigBuilder) SetMaxServerSendMsgSize(maxServerSendMsgSize string) *ProtocolConfigBuilder {
    87  	pcb.protocolConfig.MaxServerSendMsgSize = maxServerSendMsgSize
    88  	return pcb
    89  }
    90  
    91  func (pcb *ProtocolConfigBuilder) SetMaxServerRecvMsgSize(maxServerRecvMsgSize string) *ProtocolConfigBuilder {
    92  	pcb.protocolConfig.MaxServerRecvMsgSize = maxServerRecvMsgSize
    93  	return pcb
    94  }
    95  
    96  func (pcb *ProtocolConfigBuilder) Build() *ProtocolConfig {
    97  	return pcb.protocolConfig
    98  }