ExportEvents 导出事件
(ctx context.Context, query *AuditQuery, format ExportFormat)
| 811 | |
| 812 | // ExportEvents 导出事件 |
| 813 | func (al *InMemoryAuditLog) ExportEvents(ctx context.Context, query *AuditQuery, format ExportFormat) ([]byte, error) { |
| 814 | result, err := al.QueryEvents(ctx, query) |
| 815 | if err != nil { |
| 816 | return nil, err |
| 817 | } |
| 818 | |
| 819 | switch format { |
| 820 | case ExportFormatJSON: |
| 821 | return json.MarshalIndent(result.Events, "", " ") |
| 822 | case ExportFormatCSV: |
| 823 | return al.exportToCSV(result.Events) |
| 824 | default: |
| 825 | return nil, fmt.Errorf("unsupported export format: %s", format) |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | // exportToCSV 导出为CSV格式 |
| 830 | func (al *InMemoryAuditLog) exportToCSV(events []*AuditEvent) ([]byte, error) { |
nothing calls this directly
no test coverage detected