Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
66c4e16397 | ||
|
59ac25d85d | ||
|
6d316c475f | ||
|
39af901d9d | ||
|
a518073e67 |
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
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
generated
Normal file
8
.idea/modules.xml
generated
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
generated
Normal file
9
.idea/nacos-viper-remote.iml
generated
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
generated
Normal file
6
.idea/vcs.xml
generated
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>
|
@@ -1,4 +1,4 @@
|
|||||||
# nacos-viper-remote
|
# Viper remote for Nacos
|
||||||
|
|
||||||
Golang configuration,use to Viper reading from remote Nacos config systems. Viper remote for Naocs.
|
Golang configuration,use to Viper reading from remote Nacos config systems. Viper remote for Naocs.
|
||||||
|
|
||||||
|
44
config_remote_provider.go
Normal file
44
config_remote_provider.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package nacos_viper_remote
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ViperRemoteProvider struct {
|
||||||
|
configType string
|
||||||
|
configSet string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRemoteProvider(configType string) *ViperRemoteProvider {
|
||||||
|
return &ViperRemoteProvider{
|
||||||
|
configType: configType,
|
||||||
|
configSet: "yoyogo.cloud.discovery.metadata"}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (provider *ViperRemoteProvider) GetProvider(runtime_viper *viper.Viper) *viper.Viper {
|
||||||
|
var option *Option
|
||||||
|
err := runtime_viper.Sub(provider.configSet).Unmarshal(&option)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
SetOptions(option)
|
||||||
|
remote_viper := viper.New()
|
||||||
|
err = remote_viper.AddRemoteProvider("nacos", "localhost", "")
|
||||||
|
if provider.configType == "" {
|
||||||
|
provider.configType = "yaml"
|
||||||
|
}
|
||||||
|
remote_viper.SetConfigType(provider.configType)
|
||||||
|
err = remote_viper.ReadRemoteConfig()
|
||||||
|
if err == nil {
|
||||||
|
err = remote_viper.WatchRemoteConfigOnChannel()
|
||||||
|
if err == nil {
|
||||||
|
fmt.Println("used remote viper")
|
||||||
|
return remote_viper
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return runtime_viper
|
||||||
|
}
|
@@ -8,7 +8,7 @@ yoyogo:
|
|||||||
strategy: "round-robin" # round-robin , weight-time , random
|
strategy: "round-robin" # round-robin , weight-time , random
|
||||||
type: "nacos"
|
type: "nacos"
|
||||||
metadata:
|
metadata:
|
||||||
url: "120.53.133.30"
|
url: "localhost"
|
||||||
port: 80
|
port: 80
|
||||||
namespace: "public"
|
namespace: "public"
|
||||||
group: "DEFAULT_GROUP"
|
group: "DEFAULT_GROUP"
|
||||||
@@ -17,4 +17,4 @@ yoyogo:
|
|||||||
auth:
|
auth:
|
||||||
enable: true
|
enable: true
|
||||||
username: "root"
|
username: "root"
|
||||||
password: "1234"
|
password: "1234"
|
||||||
|
Reference in New Issue
Block a user