mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-19 22:28:45 +05:00
InterfaceAsString using ToJSON to convert unknown fields
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user