Skip to content

Commit a9d1410

Browse files
committed
infile: lazy map init
1 parent c418c1b commit a9d1410

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

infile.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ var (
2121
readerRegister map[string]func() io.Reader
2222
)
2323

24-
func init() {
25-
fileRegister = make(map[string]bool)
26-
readerRegister = make(map[string]func() io.Reader)
27-
}
28-
2924
// RegisterLocalFile adds the given file to the file whitelist,
3025
// so that it can be used by "LOAD DATA LOCAL INFILE <filepath>".
3126
// Alternatively you can allow the use of all local files with
@@ -38,6 +33,11 @@ func init() {
3833
// ...
3934
//
4035
func RegisterLocalFile(filePath string) {
36+
// lazy map init
37+
if fileRegister == nil {
38+
fileRegister = make(map[string]bool)
39+
}
40+
4141
fileRegister[strings.Trim(filePath, `"`)] = true
4242
}
4343

@@ -62,6 +62,11 @@ func DeregisterLocalFile(filePath string) {
6262
// ...
6363
//
6464
func RegisterReaderHandler(name string, handler func() io.Reader) {
65+
// lazy map init
66+
if readerRegister == nil {
67+
readerRegister = make(map[string]func() io.Reader)
68+
}
69+
6570
readerRegister[name] = handler
6671
}
6772

0 commit comments

Comments
 (0)