|
|
|
@ -25,7 +25,12 @@ const ( |
|
|
|
|
properties = "properties" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
var formats map[string]struct{} |
|
|
|
|
var formats = map[string]struct{}{ |
|
|
|
|
yaml: {}, |
|
|
|
|
yml: {}, |
|
|
|
|
json: {}, |
|
|
|
|
properties: {}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Option is apollo option
|
|
|
|
|
type Option func(*options) |
|
|
|
@ -130,8 +135,10 @@ func NewSource(opts ...Option) config.Source { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func format(ns string) string { |
|
|
|
|
arr := strings.Split(ns, ".") |
|
|
|
|
suffix := arr[len(arr)-1] |
|
|
|
|
var ( |
|
|
|
|
arr = strings.Split(ns, ".") |
|
|
|
|
suffix = arr[len(arr)-1] |
|
|
|
|
) |
|
|
|
|
if len(arr) <= 1 || suffix == properties { |
|
|
|
|
return json |
|
|
|
|
} |
|
|
|
@ -144,8 +151,10 @@ func format(ns string) string { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (e *apollo) load() []*config.KeyValue { |
|
|
|
|
kvs := make([]*config.KeyValue, 0) |
|
|
|
|
namespaces := strings.Split(e.opt.namespace, ",") |
|
|
|
|
var ( |
|
|
|
|
kvs = make([]*config.KeyValue, 0) |
|
|
|
|
namespaces = strings.Split(e.opt.namespace, ",") |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
for _, ns := range namespaces { |
|
|
|
|
if !e.opt.originConfig { |
|
|
|
@ -225,10 +234,12 @@ func (e *apollo) Watch() (config.Watcher, error) { |
|
|
|
|
// resolve convert kv pair into one map[string]interface{} by split key into different
|
|
|
|
|
// map level. such as: app.name = "application" => map[app][name] = "application"
|
|
|
|
|
func resolve(key string, value interface{}, target map[string]interface{}) { |
|
|
|
|
// expand key "aaa.bbb" into map[aaa]map[bbb]interface{}
|
|
|
|
|
keys := strings.Split(key, ".") |
|
|
|
|
last := len(keys) - 1 |
|
|
|
|
cursor := target |
|
|
|
|
var ( |
|
|
|
|
// expand key "aaa.bbb" into map[aaa]map[bbb]interface{}
|
|
|
|
|
keys = strings.Split(key, ".") |
|
|
|
|
last = len(keys) - 1 |
|
|
|
|
cursor = target |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
for i, k := range keys { |
|
|
|
|
if i == last { |
|
|
|
@ -275,12 +286,3 @@ func genKey(ns, sub string) string { |
|
|
|
|
|
|
|
|
|
return ns + "." + sub |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func init() { |
|
|
|
|
formats = make(map[string]struct{}) |
|
|
|
|
|
|
|
|
|
formats[yaml] = struct{}{} |
|
|
|
|
formats[yml] = struct{}{} |
|
|
|
|
formats[json] = struct{}{} |
|
|
|
|
formats[properties] = struct{}{} |
|
|
|
|
} |
|
|
|
|