-
Notifications
You must be signed in to change notification settings - Fork 929
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
Imp: load the configure file in another way #1099
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package config | ||
|
||
import ( | ||
"github.com/apache/dubbo-go/common/extension" | ||
"github.com/apache/dubbo-go/common/logger" | ||
"log" | ||
) | ||
|
||
type LoaderInitOption interface { | ||
init() | ||
apply() | ||
} | ||
|
||
type optionFunc struct { | ||
initFunc func() | ||
applyFunc func() | ||
} | ||
|
||
func (f *optionFunc) init() { | ||
f.initFunc() | ||
} | ||
|
||
func (f *optionFunc) apply() { | ||
f.applyFunc() | ||
} | ||
|
||
func ConsumerInitOption(confConFile string) LoaderInitOption { | ||
return consumerInitOption(confConFile, false) | ||
} | ||
|
||
func ConsumerMustInitOption(confConFile string) LoaderInitOption { | ||
return consumerInitOption(confConFile, true) | ||
} | ||
|
||
func consumerInitOption(confConFile string, must bool) LoaderInitOption { | ||
return &optionFunc{ | ||
func() { | ||
if consumerConfig != nil && !must { | ||
return | ||
} | ||
if errCon := ConsumerInit(confConFile); errCon != nil { | ||
log.Printf("[consumerInit] %#v", errCon) | ||
consumerConfig = nil | ||
} else if confBaseFile == "" { | ||
// Check if there are some important key fields missing, | ||
// if so, we set a default value for it | ||
setDefaultValue(consumerConfig) | ||
// Even though baseConfig has been initialized, we override it | ||
// because we think read from config file is correct config | ||
baseConfig = &consumerConfig.BaseConfig | ||
} | ||
}, | ||
func() { | ||
loadConsumerConfig() | ||
}, | ||
} | ||
} | ||
|
||
func ProviderInitOption(confProFile string) LoaderInitOption { | ||
return providerInitOption(confProFile, false) | ||
} | ||
|
||
func ProviderMustInitOption(confProFile string) LoaderInitOption { | ||
return providerInitOption(confProFile, true) | ||
} | ||
|
||
func providerInitOption(confProFile string, must bool) LoaderInitOption { | ||
return &optionFunc{ | ||
func() { | ||
if providerConfig != nil && !must { | ||
return | ||
} | ||
if errPro := ProviderInit(confProFile); errPro != nil { | ||
log.Printf("[providerInit] %#v", errPro) | ||
providerConfig = nil | ||
} else if confBaseFile == "" { | ||
// Check if there are some important key fields missing, | ||
// if so, we set a default value for it | ||
setDefaultValue(providerConfig) | ||
// Even though baseConfig has been initialized, we override it | ||
// because we think read from config file is correct config | ||
baseConfig = &providerConfig.BaseConfig | ||
} | ||
}, | ||
func() { | ||
loadProviderConfig() | ||
}, | ||
} | ||
} | ||
|
||
func RouterInitOption(crf string) LoaderInitOption { | ||
return &optionFunc{ | ||
func() { | ||
confRouterFile = crf | ||
}, | ||
func() { | ||
initRouter() | ||
}, | ||
} | ||
} | ||
|
||
func BaseInitOption(cbf string) LoaderInitOption { | ||
return &optionFunc{ | ||
func() { | ||
if cbf == "" { | ||
return | ||
} | ||
confBaseFile = cbf | ||
if err := BaseInit(cbf); err != nil { | ||
log.Printf("[BaseInit] %#v", err) | ||
baseConfig = nil | ||
} | ||
}, | ||
func() { | ||
// init the global event dispatcher | ||
extension.SetAndInitGlobalDispatcher(GetBaseConfig().EventDispatcherType) | ||
|
||
// start the metadata report if config set | ||
if err := startMetadataReport(GetApplicationConfig().MetadataType, GetBaseConfig().MetadataReportConfig); err != nil { | ||
logger.Errorf("Provider starts metadata report error, and the error is {%#v}", err) | ||
return | ||
} | ||
}, | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey, guy, move it to the 3rd import block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's done