-
Notifications
You must be signed in to change notification settings - Fork 1
/
exporter.go
39 lines (31 loc) · 958 Bytes
/
exporter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package fixture
import (
"fmt"
"github.com/iFaceless/fixture/exporters"
)
type Exporter interface {
Export(tableName string, columns []string, rawRows [][][]byte) ([]byte, error)
}
var exporterMap = make(map[DataFormat]Exporter)
func LookupExporter(format DataFormat) Exporter {
exporter, ok := exporterMap[format]
if !ok {
panic(fmt.Sprintf("exporter not found for data format '%s'", format))
}
return exporter
}
func RegisterExporter(dataFmt DataFormat, ext string, exporter Exporter) {
if oldFmt, ok := extToDataFmtMapping[ext]; ok {
if oldFmt != dataFmt {
panic(fmt.Sprintf("old data format of extension '%s' dose not match the new one", ext))
}
} else {
extToDataFmtMapping[ext] = dataFmt
}
exporterMap[dataFmt] = exporter
}
func init() {
RegisterExporter(SQL, ".sql", exporters.NewSQLExporter())
RegisterExporter(JSON, ".json", exporters.NewJsonExporter())
RegisterExporter(YAML, ".yml", exporters.NewYamlExporter())
}