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