|
|
@ -24,21 +24,19 @@ type customChangeListener struct { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (c *customChangeListener) onChange(namespace string, changes map[string]*storage.ConfigChange) []*config.KeyValue { |
|
|
|
func (c *customChangeListener) onChange(namespace string, changes map[string]*storage.ConfigChange) []*config.KeyValue { |
|
|
|
kv := make([]*config.KeyValue, 0, 2) |
|
|
|
if strings.Contains(namespace, ".") && !strings.HasSuffix(namespace, "."+properties) && isOriginConfig(namespace) { |
|
|
|
if strings.Contains(namespace, ".") && !strings.HasSuffix(namespace, "."+properties) && |
|
|
|
|
|
|
|
(format(namespace) == yaml || format(namespace) == yml || format(namespace) == json) { |
|
|
|
|
|
|
|
value, err := c.apollo.client.GetConfigCache(namespace).Get("content") |
|
|
|
value, err := c.apollo.client.GetConfigCache(namespace).Get("content") |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Warnw("apollo get config failed", "err", err) |
|
|
|
log.Warnw("apollo get config failed", "err", err) |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
kv = append(kv, &config.KeyValue{ |
|
|
|
return []*config.KeyValue{ |
|
|
|
|
|
|
|
{ |
|
|
|
Key: namespace, |
|
|
|
Key: namespace, |
|
|
|
Value: []byte(value.(string)), |
|
|
|
Value: []byte(value.(string)), |
|
|
|
Format: format(namespace), |
|
|
|
Format: format(namespace), |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
} |
|
|
|
return kv |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
next := make(map[string]interface{}) |
|
|
|
next := make(map[string]interface{}) |
|
|
@ -48,19 +46,18 @@ func (c *customChangeListener) onChange(namespace string, changes map[string]*st |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
f := format(namespace) |
|
|
|
f := format(namespace) |
|
|
|
codec := encoding.GetCodec(f) |
|
|
|
val, err := encoding.GetCodec(f).Marshal(next) |
|
|
|
val, err := codec.Marshal(next) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Warnf("apollo could not handle namespace %s: %v", namespace, err) |
|
|
|
log.Warnf("apollo could not handle namespace %s: %v", namespace, err) |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
kv = append(kv, &config.KeyValue{ |
|
|
|
return []*config.KeyValue{ |
|
|
|
|
|
|
|
{ |
|
|
|
Key: namespace, |
|
|
|
Key: namespace, |
|
|
|
Value: val, |
|
|
|
Value: val, |
|
|
|
Format: f, |
|
|
|
Format: f, |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
} |
|
|
|
return kv |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (c *customChangeListener) OnChange(changeEvent *storage.ChangeEvent) { |
|
|
|
func (c *customChangeListener) OnChange(changeEvent *storage.ChangeEvent) { |
|
|
|