Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
a67dc7b1ca | ||
|
984f887d45 | ||
|
c2df5af4f0 | ||
|
badd6647dc | ||
|
66c4e16397 |
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>
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 yoyofx
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@@ -6,17 +6,19 @@ import (
|
||||
)
|
||||
|
||||
type ViperRemoteProvider struct {
|
||||
configType string
|
||||
configSet string
|
||||
}
|
||||
|
||||
func NewRemoteProvider() *ViperRemoteProvider {
|
||||
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("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()
|
||||
|
@@ -18,3 +18,8 @@ yoyogo:
|
||||
enable: true
|
||||
username: "root"
|
||||
password: "1234"
|
||||
endpoint: ""
|
||||
regionId: ""
|
||||
accessKey: ""
|
||||
secretKey: ""
|
||||
openKMS: false
|
||||
|
2
go.mod
2
go.mod
@@ -3,6 +3,6 @@ module github.com/yoyofxteam/nacos-viper-remote
|
||||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/spf13/viper v1.7.1
|
||||
github.com/nacos-group/nacos-sdk-go v1.0.7
|
||||
github.com/spf13/viper v1.8.1
|
||||
)
|
||||
|
@@ -34,9 +34,15 @@ func NewNacosConfigManager(option *Option) (*nacosConfigManager, error) {
|
||||
MaxAge: 3,
|
||||
LogLevel: "info",
|
||||
}
|
||||
|
||||
if option.Auth != nil && option.Auth.Enable {
|
||||
clientConfig.Username = option.Auth.User
|
||||
clientConfig.Password = option.Auth.Password
|
||||
clientConfig.Endpoint = option.Auth.Endpoint
|
||||
clientConfig.RegionId = option.Auth.RegionId
|
||||
clientConfig.AccessKey = option.Auth.AccessKey
|
||||
clientConfig.SecretKey = option.Auth.SecretKey
|
||||
clientConfig.OpenKMS = option.Auth.OpenKMS
|
||||
}
|
||||
client, err := clients.CreateConfigClient(map[string]interface{}{
|
||||
"serverConfigs": serverConfigs,
|
||||
|
@@ -17,4 +17,15 @@ type Auth struct {
|
||||
Enable bool `mapstructure:"enable"`
|
||||
User string `mapstructure:"username"`
|
||||
Password string `mapstructure:"password"`
|
||||
|
||||
// ACM Endpoint
|
||||
Endpoint string `mapstructure:"endpoint"`
|
||||
// ACM RegionId
|
||||
RegionId string `mapstructure:"regionId"`
|
||||
// ACM AccessKey
|
||||
AccessKey string `mapstructure:"accessKey"`
|
||||
// ACM SecretKey
|
||||
SecretKey string `mapstructure:"secretKey"`
|
||||
// ACM OpenKMS
|
||||
OpenKMS bool `mapstructure:"openKMS"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user