provider with config type

This commit is contained in:
yoyofx 2021-05-12 13:56:58 +08:00
parent 59ac25d85d
commit 66c4e16397
5 changed files with 41 additions and 5 deletions

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/nacos-viper-remote.iml" filepath="$PROJECT_DIR$/.idea/nacos-viper-remote.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -6,17 +6,19 @@ import (
)
type ViperRemoteProvider struct {
configSet string
configType string
configSet string
}
func NewRemoteProvider() *ViperRemoteProvider {
func NewRemoteProvider(configType string) *ViperRemoteProvider {
return &ViperRemoteProvider{
configSet: "yoyogo.cloud.discovery.metadata"}
configType: configType,
configSet: "yoyogo.cloud.discovery.metadata"}
}
func (provider *ViperRemoteProvider) GetProvider(runtime_viper *viper.Viper) *viper.Viper {
var option *Option
err := runtime_viper.Sub("yoyogo.cloud.discovery.metadata").Unmarshal(&option)
err := runtime_viper.Sub(provider.configSet).Unmarshal(&option)
if err != nil {
panic(err)
return nil
@ -24,7 +26,10 @@ func (provider *ViperRemoteProvider) GetProvider(runtime_viper *viper.Viper) *vi
SetOptions(option)
remote_viper := viper.New()
err = remote_viper.AddRemoteProvider("nacos", "localhost", "")
remote_viper.SetConfigType("yaml")
if provider.configType == "" {
provider.configType = "yaml"
}
remote_viper.SetConfigType(provider.configType)
err = remote_viper.ReadRemoteConfig()
if err == nil {
err = remote_viper.WatchRemoteConfigOnChannel()