-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* uddapte: nacos config * Add: nacos config center * update: nacos config * add ut * fmt * clean code for CI * update: listen * Add go sum * update: fix config_center UT, ignore the cache and log dir * fix UT * update: off nacos_config_center UT
- Loading branch information
Showing
14 changed files
with
680 additions
and
24 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ samples/dubbogo/simple/server/app/app | |
/logs | ||
/.idea | ||
/.vscode | ||
.cache | ||
.log | ||
|
||
.DS_Store | ||
vendor/ | ||
|
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,26 @@ | ||
/* | ||
* 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 main | ||
|
||
type Deployer interface { | ||
initialize() error | ||
|
||
start() error | ||
|
||
stop() error | ||
} |
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,28 @@ | ||
/* | ||
* 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 configcenter | ||
|
||
type ( | ||
ConfigClient interface { | ||
LoadConfig(properties map[string]interface{}) (string, error) | ||
|
||
ListenConfig(properties map[string]interface{}) (err error) | ||
} | ||
|
||
ListenConfig func(data string) | ||
) |
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,124 @@ | ||
/* | ||
* 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 configcenter | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
import ( | ||
"github.com/ghodss/yaml" | ||
) | ||
|
||
import ( | ||
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/logger" | ||
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/model" | ||
) | ||
|
||
const ( | ||
KEY_CONFIG_TYPE_NACOS = "nacos" | ||
) | ||
|
||
var Parsers = map[string]func(data []byte, v interface{}) error{ | ||
".yaml": ParseYamlBytes, | ||
".yml": ParseYamlBytes, | ||
} | ||
|
||
type ( | ||
Load interface { | ||
LoadConfigs(boot *model.Bootstrap, opts ...Option) (v *model.Bootstrap, err error) | ||
} | ||
|
||
Option func(opt *Options) | ||
|
||
Options struct { | ||
Remote bool | ||
DataId string | ||
Group string | ||
path string | ||
parser string | ||
} | ||
) | ||
|
||
type DefaultConfigLoad struct { | ||
bootConfig *model.Bootstrap | ||
configClient ConfigClient | ||
} | ||
|
||
func NewConfigLoad(bootConfig *model.Bootstrap) *DefaultConfigLoad { | ||
|
||
var configClient ConfigClient | ||
|
||
// config center load | ||
if strings.EqualFold(bootConfig.Config.Type, KEY_CONFIG_TYPE_NACOS) { | ||
configClient, _ = NewNacosConfig(bootConfig) | ||
} | ||
|
||
if configClient == nil { | ||
logger.Warnf("no remote config-center") | ||
return nil | ||
} | ||
|
||
return &DefaultConfigLoad{ | ||
bootConfig: bootConfig, | ||
configClient: configClient, | ||
} | ||
} | ||
|
||
func (d *DefaultConfigLoad) LoadConfigs(boot *model.Bootstrap, opts ...Option) (v *model.Bootstrap, err error) { | ||
|
||
var opt Options | ||
for _, o := range opts { | ||
o(&opt) | ||
} | ||
|
||
if !opt.Remote { | ||
return nil, nil | ||
} | ||
|
||
m := map[string]interface{}{} | ||
|
||
if strings.EqualFold(boot.Config.Type, KEY_CONFIG_TYPE_NACOS) { | ||
m["dataId"] = getOrDefault(opt.DataId, DataId) | ||
m["group"] = getOrDefault(opt.Group, Group) | ||
} | ||
|
||
if len(m) == 0 { | ||
logger.Errorf("no identify properties key when load from remote config center") | ||
return boot, nil | ||
} | ||
|
||
data, err := d.configClient.LoadConfig(m) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if len(data) == 0 { | ||
logger.Errorf("the config data load from remote is nil, config center : %s", boot.Config.Type) | ||
return boot, err | ||
} | ||
|
||
err = Parsers[".yml"]([]byte(data), boot) | ||
|
||
return boot, err | ||
} | ||
|
||
func ParseYamlBytes(content []byte, v interface{}) error { | ||
return yaml.Unmarshal(content, v) | ||
} |
Oops, something went wrong.