2023-11-17 20:34:20 +05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ExportFormat string
|
|
|
|
|
|
|
|
const (
|
2023-12-30 21:14:42 +05:00
|
|
|
ExportFormatExcel ExportFormat = "XLSX"
|
|
|
|
ExportFormatCsv ExportFormat = "CSV"
|
|
|
|
ExportFormatCsvZip ExportFormat = "CSV+ZIP"
|
2023-11-17 20:34:20 +05:00
|
|
|
)
|
|
|
|
|
|
|
|
// Exporter - интерфейс экспорта
|
|
|
|
type Exporter interface {
|
|
|
|
Convert(filePath string, rows chan []any) error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e ExportFormat) GetExporter(encoding Encoding) (Exporter, error) {
|
|
|
|
switch e {
|
|
|
|
case ExportFormatExcel:
|
|
|
|
return new(XlsxExporter), nil
|
|
|
|
case ExportFormatCsv:
|
|
|
|
return &CsvExporter{Encoding: encoding}, nil
|
2023-12-30 21:14:42 +05:00
|
|
|
case ExportFormatCsvZip:
|
|
|
|
return &CsvZipExporter{Encoding: encoding}, nil
|
2023-11-17 20:34:20 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("unknown format: %s", string(e))
|
|
|
|
}
|