dubbo.apache.org/dubbo-go/v3@v3.1.1/config/application_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 "github.com/pkg/errors" 23 ) 24 25 import ( 26 "dubbo.apache.org/dubbo-go/v3/common/constant" 27 ) 28 29 // ApplicationConfig is a configuration for current applicationConfig, whether the applicationConfig is a provider or a consumer 30 type ApplicationConfig struct { 31 Organization string `default:"dubbo-go" yaml:"organization" json:"organization,omitempty" property:"organization"` 32 Name string `default:"dubbo.io" yaml:"name" json:"name,omitempty" property:"name"` 33 Module string `default:"sample" yaml:"module" json:"module,omitempty" property:"module"` 34 Group string `yaml:"group" json:"group,omitempty" property:"module"` 35 Version string `yaml:"version" json:"version,omitempty" property:"version"` 36 Owner string `default:"dubbo-go" yaml:"owner" json:"owner,omitempty" property:"owner"` 37 Environment string `yaml:"environment" json:"environment,omitempty" property:"environment"` 38 // the metadata type. remote or local 39 MetadataType string `default:"local" yaml:"metadata-type" json:"metadataType,omitempty" property:"metadataType"` 40 Tag string `yaml:"tag" json:"tag,omitempty" property:"tag"` 41 MetadataServicePort string `yaml:"metadata-service-port" json:"metadata-service-port,omitempty" property:"metadata-service-port"` 42 } 43 44 // Prefix dubbo.application 45 func (ac *ApplicationConfig) Prefix() string { 46 return constant.ApplicationConfigPrefix 47 } 48 49 // Init application config and set default value 50 func (ac *ApplicationConfig) Init() error { 51 if ac == nil { 52 return errors.New("application is null") 53 } 54 if err := ac.check(); err != nil { 55 return err 56 } 57 if ac.Name == "" { 58 ac.Name = constant.DefaultDubboApp 59 } 60 return nil 61 } 62 63 func (ac *ApplicationConfig) check() error { 64 if err := defaults.Set(ac); err != nil { 65 return err 66 } 67 return verify(ac) 68 } 69 70 func NewApplicationConfigBuilder() *ApplicationConfigBuilder { 71 return &ApplicationConfigBuilder{application: &ApplicationConfig{}} 72 } 73 74 type ApplicationConfigBuilder struct { 75 application *ApplicationConfig 76 } 77 78 func (acb *ApplicationConfigBuilder) SetOrganization(organization string) *ApplicationConfigBuilder { 79 acb.application.Organization = organization 80 return acb 81 } 82 83 func (acb *ApplicationConfigBuilder) SetName(name string) *ApplicationConfigBuilder { 84 acb.application.Name = name 85 return acb 86 } 87 88 func (acb *ApplicationConfigBuilder) SetModule(module string) *ApplicationConfigBuilder { 89 acb.application.Module = module 90 return acb 91 } 92 93 func (acb *ApplicationConfigBuilder) SetVersion(version string) *ApplicationConfigBuilder { 94 acb.application.Version = version 95 return acb 96 } 97 98 func (acb *ApplicationConfigBuilder) SetOwner(owner string) *ApplicationConfigBuilder { 99 acb.application.Owner = owner 100 return acb 101 } 102 103 func (acb *ApplicationConfigBuilder) SetEnvironment(environment string) *ApplicationConfigBuilder { 104 acb.application.Environment = environment 105 return acb 106 } 107 108 func (acb *ApplicationConfigBuilder) SetMetadataType(metadataType string) *ApplicationConfigBuilder { 109 acb.application.MetadataType = metadataType 110 return acb 111 } 112 113 func (acb *ApplicationConfigBuilder) Build() *ApplicationConfig { 114 return acb.application 115 }