InterfaceAsString using ToJSON to convert unknown fields

This commit is contained in:
DanB
2018-05-29 19:16:03 +02:00
parent 52b440713a
commit 25730575ee
2 changed files with 10 additions and 6 deletions

View File

@@ -558,6 +558,8 @@ func (cdr *CDR) AsExportRecord(exportFields []*config.CfgCdrField, httpSkipTlsCh
if err == utils.ErrFilterNotPassingNoCaps {
continue // not exporting this field value
}
utils.Logger.Warning(fmt.Sprintf("<CDR> error: %s exporting field: %s, CDR: %s\n",
err.Error(), utils.ToJSON(cfgFld), utils.ToJSON(cdr)))
return nil, err
} else {
expRecord = append(expRecord, fmtOut)

View File

@@ -50,8 +50,12 @@ func CastFieldIfToString(fld interface{}) (string, bool) {
case time.Duration:
strVal = fld.(time.Duration).String()
converted = true
case string:
strVal = fld.(string)
converted = true
default: // Maybe we are lucky and the value converts to string
strVal, converted = fld.(string)
strVal = ToJSON(fld)
converted = true
}
return strVal, converted
}
@@ -245,12 +249,10 @@ func IfaceAsString(fld interface{}) (out string, err error) {
return fld.(time.Duration).String(), nil
case time.Time:
return fld.(time.Time).Format(time.RFC3339), nil
case string:
return fld.(string), nil
default: // Maybe we are lucky and the value converts to string
if out, canCast := fld.(string); !canCast {
return "", ErrNotConvertibleNoCaps
} else {
return out, nil
}
return ToJSON(fld), nil
}
}