1 回答

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超6個贊
我通過更改解決了它:
var reqJSONBody, resJSONBody interface{}
if len(*reqBody) > 0 {
if err := json.Unmarshal(*reqBody, &reqJSONBody); err != nil {
gl.ServiceLogger.Error("error parsing the request body: ", requestURI, err)
}
encryptPrivacyField(&reqJSONBody)
}
所以我必須encryptPrivacyField像這樣改變方法:
func encryptPrivacyField(data *interface{}) {
switch reflect.TypeOf(*data).Kind() {
case reflect.Map:
for _, field := range getPrivacyFieldList() {
if item, ok := (*data).(map[string]interface{})[field]; ok && item != nil {
(*data).(map[string]interface{})[field] = db.NewEncString(fmt.Sprintf("%v", (*data).(map[string]interface{})[field]))
}
}
for _, field := range getHashFieldList() {
if item, ok := (*data).(map[string]interface{})[field]; ok && item != nil {
(*data).(map[string]interface{})[field] = db.NewHashString(fmt.Sprintf("%v", (*data).(map[string]interface{})[field]))
}
}
case reflect.Slice:
for index, _ := range (*data).([]interface{}) {
encryptPrivacyField(&(*data).([]interface{})[index])
}
}
}
- 1 回答
- 0 關(guān)注
- 142 瀏覽
添加回答
舉報(bào)