provider with config type
This commit is contained in:
parent
59ac25d85d
commit
66c4e16397
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal 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
8
.idea/modules.xml
Normal 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>
|
9
.idea/nacos-viper-remote.iml
Normal file
9
.idea/nacos-viper-remote.iml
Normal 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
6
.idea/vcs.xml
Normal 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>
|
@ -6,17 +6,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ViperRemoteProvider struct {
|
type ViperRemoteProvider struct {
|
||||||
|
configType string
|
||||||
configSet string
|
configSet string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRemoteProvider() *ViperRemoteProvider {
|
func NewRemoteProvider(configType string) *ViperRemoteProvider {
|
||||||
return &ViperRemoteProvider{
|
return &ViperRemoteProvider{
|
||||||
|
configType: configType,
|
||||||
configSet: "yoyogo.cloud.discovery.metadata"}
|
configSet: "yoyogo.cloud.discovery.metadata"}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (provider *ViperRemoteProvider) GetProvider(runtime_viper *viper.Viper) *viper.Viper {
|
func (provider *ViperRemoteProvider) GetProvider(runtime_viper *viper.Viper) *viper.Viper {
|
||||||
var option *Option
|
var option *Option
|
||||||
err := runtime_viper.Sub("yoyogo.cloud.discovery.metadata").Unmarshal(&option)
|
err := runtime_viper.Sub(provider.configSet).Unmarshal(&option)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
return nil
|
return nil
|
||||||
@ -24,7 +26,10 @@ func (provider *ViperRemoteProvider) GetProvider(runtime_viper *viper.Viper) *vi
|
|||||||
SetOptions(option)
|
SetOptions(option)
|
||||||
remote_viper := viper.New()
|
remote_viper := viper.New()
|
||||||
err = remote_viper.AddRemoteProvider("nacos", "localhost", "")
|
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()
|
err = remote_viper.ReadRemoteConfig()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = remote_viper.WatchRemoteConfigOnChannel()
|
err = remote_viper.WatchRemoteConfigOnChannel()
|
||||||
|
Loading…
Reference in New Issue
Block a user