apolloconfig / agollo

🚀Go client for ctrip/apollo (https://github.com/apolloconfig/apollo)
https://www.apolloconfig.com
Apache License 2.0
708 stars 189 forks source link

[BUG] #277

Closed coffeeTu-code closed 1 year ago

coffeeTu-code commented 1 year ago

为什么在没有完成parser的情况下改变了 apolloConfig.Configurations ,这会导致数据前后不一致

func processJSONFiles(b []byte, callback http.CallBack) (o interface{}, err error) { apolloConfig := &config.ApolloConfig{} apolloConfig.NamespaceName = callback.Namespace

configurations := make(map[string]interface{}, 0)
apolloConfig.Configurations = configurations
err = json.Unmarshal(b, &apolloConfig.Configurations)

if utils.IsNotNil(err) {
    return nil, err
}

parser := extension.GetFormatParser(constant.ConfigFileFormat(path.Ext(apolloConfig.NamespaceName)))
if parser == nil {
    parser = extension.GetFormatParser(constant.DEFAULT)
}

if parser == nil {
    return apolloConfig, nil
}

content, ok := configurations[defaultContentKey]
if !ok {
    content = string(b)
}
m, err := parser.Parse(content)
if err != nil {
    log.Debugf("GetContent fail ! error: %v", err)
}

if len(m) > 0 {
    apolloConfig.Configurations = m
}
return apolloConfig, nil

}

nobodyiam commented 1 year ago

Would you please help to submit a unit test to reproduce this bug and it would also be great to submit a patch for that.

zouyx commented 1 year ago

为什么在没有完成parser的情况下改变了 apolloConfig.Configurations ,这会导致数据前后不一致

func processJSONFiles(b []byte, callback http.CallBack) (o interface{}, err error) { apolloConfig := &config.ApolloConfig{} apolloConfig.NamespaceName = callback.Namespace

configurations := make(map[string]interface{}, 0)
apolloConfig.Configurations = configurations
err = json.Unmarshal(b, &apolloConfig.Configurations)

if utils.IsNotNil(err) {
  return nil, err
}

parser := extension.GetFormatParser(constant.ConfigFileFormat(path.Ext(apolloConfig.NamespaceName)))
if parser == nil {
  parser = extension.GetFormatParser(constant.DEFAULT)
}

if parser == nil {
  return apolloConfig, nil
}

content, ok := configurations[defaultContentKey]
if !ok {
  content = string(b)
}
m, err := parser.Parse(content)
if err != nil {
  log.Debugf("GetContent fail ! error: %v", err)
}

if len(m) > 0 {
  apolloConfig.Configurations = m
}
return apolloConfig, nil

}

不太明白遇到了什么问题?是否能提供一下背景和问题描述,或者 unit test 也可以。