dubbo.apache.org/dubbo-go/v3@v3.1.1/config/service_discovery_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 "dubbo.apache.org/dubbo-go/v3/common/constant" 22 ) 23 24 // ServiceDiscoveryConfig will be used to create 25 type ServiceDiscoveryConfig struct { 26 // Protocol indicate which implementation will be used. 27 // for example, if the Protocol is nacos, it means that we will use nacosServiceDiscovery 28 Protocol string `yaml:"protocol" json:"protocol,omitempty" property:"protocol"` 29 // Group, usually you don't need to config this field. 30 // you can use this to do some isolation 31 Group string `yaml:"group" json:"group,omitempty"` 32 // RemoteRef is the reference point to RemoteConfig which will be used to create remotes instances. 33 RemoteRef string `yaml:"remote_ref" json:"remote_ref,omitempty" property:"remote_ref"` 34 } 35 36 func (ServiceDiscoveryConfig) Prefix() string { 37 return constant.ServiceDiscPrefix 38 } 39 40 func (ServiceDiscoveryConfig) Init() error { 41 return nil 42 } 43 44 func NewServiceDiscoveryConfigBuilder() *ServiceDiscoveryConfigBuilder { 45 return &ServiceDiscoveryConfigBuilder{ 46 serviceDiscoveryConfig: &ServiceDiscoveryConfig{}, 47 } 48 } 49 50 type ServiceDiscoveryConfigBuilder struct { 51 serviceDiscoveryConfig *ServiceDiscoveryConfig 52 } 53 54 func (sdcb *ServiceDiscoveryConfigBuilder) SetProtocol(protocol string) *ServiceDiscoveryConfigBuilder { 55 sdcb.serviceDiscoveryConfig.Protocol = protocol 56 return sdcb 57 } 58 59 func (sdcb *ServiceDiscoveryConfigBuilder) SetGroup(group string) *ServiceDiscoveryConfigBuilder { 60 sdcb.serviceDiscoveryConfig.Group = group 61 return sdcb 62 } 63 64 func (sdcb *ServiceDiscoveryConfigBuilder) SetRemoteRef(remoteRef string) *ServiceDiscoveryConfigBuilder { 65 sdcb.serviceDiscoveryConfig.RemoteRef = remoteRef 66 return sdcb 67 } 68 69 func (sdcb *ServiceDiscoveryConfigBuilder) Build() *ServiceDiscoveryConfig { 70 if err := sdcb.serviceDiscoveryConfig.Init(); err != nil { 71 panic(err) 72 } 73 return sdcb.serviceDiscoveryConfig 74 }