Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ftr: provide a default config #1073

Merged
merged 9 commits into from
Mar 21, 2021
7 changes: 7 additions & 0 deletions common/constant/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,10 @@ const (
const (
SERVICE_DISCOVERY_DEFAULT_GROUP = "DEFAULT_GROUP"
)

const (
DEFAULT_PROVIDER_CONF_FILE_PATH = "../profiles/dev/server.yml"
DEFAULT_CONSUMER_CONF_FILE_PATH = "../profiles/dev/client.yml"
DEFAULT_LOG_CONF_FILE_PATH = "../profiles/dev/log.yml"
DEFAULT_ROUTER_CONF_FILE_PATH = "../profiles/dev/router.yml"
)
3 changes: 3 additions & 0 deletions common/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ func init() {
for len(fs.Args()) != 0 {
fs.Parse(fs.Args()[1:])
}
if *logConfFile == "" {
*logConfFile = constant.DEFAULT_LOG_CONF_FILE_PATH
}
err := InitLog(*logConfFile)
if err != nil {
log.Printf("[InitLog] warn: %v", err)
Expand Down
55 changes: 45 additions & 10 deletions config/config_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,58 @@ func init() {
fs.Parse(fs.Args()[1:])
}

if confConFile == "" {
confConFile = constant.DEFAULT_CONSUMER_CONF_FILE_PATH
}
if confProFile == "" {
confProFile = constant.DEFAULT_PROVIDER_CONF_FILE_PATH
}
if confRouterFile == "" {
confRouterFile = constant.DEFAULT_ROUTER_CONF_FILE_PATH
}

if errCon := ConsumerInit(confConFile); errCon != nil {
log.Printf("[consumerInit] %#v", errCon)
consumerConfig = nil
} else {
// Even though baseConfig has been initialized, we override it
// because we think read from config file is correct config
baseConfig = &consumerConfig.BaseConfig
//consumerConfig = nil
consumerConfig = NewConsumerConfig(
WithConsumerAppConfig(NewDefaultApplicationConfig()), // default app config
WithConsumerConnTimeout(time.Second*3), // timeout
WithConsumerRequestTimeout(time.Second*3), // timeout
WithConsumerRegistryConfig("demoZk", NewDefaultRegistryConfig("zookeeper")), // registry config
WithConsumerReferenceConfig("UserProvider", NewReferenceConfigByAPI( // set refer config
WithReferenceRegistry("demoZk"), // registry key
WithReferenceProtocol("dubbo"), // protocol
WithReferenceInterface("com.ikurento.user.UserProvider"), // interface name
WithReferenceMethod("GetUser", "3", "random"), // method and lb
WithReferenceCluster("failover"),
)),
)
}
// Even though baseConfig has been initialized, we override it
// because we think read from config file is correct config
baseConfig = &consumerConfig.BaseConfig

if errPro := ProviderInit(confProFile); errPro != nil {
log.Printf("[providerInit] %#v", errPro)
providerConfig = nil
} else {
// Even though baseConfig has been initialized, we override it
// because we think read from config file is correct config
baseConfig = &providerConfig.BaseConfig
providerConfig = NewProviderConfig(
WithProviderAppConfig(NewDefaultApplicationConfig()),
WithProviderProtocol("dubbo", "dubbo", "20000"), // protocol and port
WithProviderRegistry("demoZk", NewDefaultRegistryConfig("zookeeper")), // registry config
WithProviderServices("UserProvider", NewServiceConfigByAPI(
WithServiceRegistry("demoZk"), // registry key, equal to upper line
WithServiceProtocol("dubbo"), // export protocol
WithServiceInterface("com.ikurento.user.UserProvider"), // interface id
WithServiceLoadBalance("random"), // lb
WithServiceWarmUpTime("100"),
WithServiceCluster("failover"),
WithServiceMethod("GetUser", "1", "random"),
)),
)
}
// Even though baseConfig has been initialized, we override it
// because we think read from config file is correct config
baseConfig = &providerConfig.BaseConfig

}

func checkRegistries(registries map[string]*RegistryConfig, singleRegistry *RegistryConfig) {
Expand Down