29 lines
554 B
Go
29 lines
554 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
)
|
||
|
|
||
|
type ExportFormat string
|
||
|
|
||
|
const (
|
||
|
ExportFormatExcel ExportFormat = "XLSX"
|
||
|
ExportFormatCsv ExportFormat = "CSV"
|
||
|
)
|
||
|
|
||
|
// 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
|
||
|
}
|
||
|
|
||
|
return nil, fmt.Errorf("unknown format: %s", string(e))
|
||
|
}
|