Skip to content

Commit e08c23b

Browse files
committed
Introduce RegisterReaderHandlerWithConfig
It is the same as RegisterReaderHandler, but receives a copy of the Config which is be needed to correctly encode the TSV. (For example for the Location). issue go-sql-driver#1416
1 parent 8503110 commit e08c23b

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

infile.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
var (
2020
fileRegister map[string]bool
2121
fileRegisterLock sync.RWMutex
22-
readerRegister map[string]func() io.Reader
22+
readerRegister map[string]func(*Config) io.Reader
2323
readerRegisterLock sync.RWMutex
2424
)
2525

@@ -66,10 +66,21 @@ func DeregisterLocalFile(filePath string) {
6666
// if err != nil {
6767
// ...
6868
func RegisterReaderHandler(name string, handler func() io.Reader) {
69+
RegisterReaderHandlerWithConfig(name, func(*Config) io.Reader {
70+
return handler()
71+
})
72+
}
73+
74+
// RegisterReaderHandlerWithConfig is like RegisterReaderHandler but the
75+
// callback receives a copy of the configuration. The configuration should not
76+
// be modified.
77+
// This allows the caller to receive information about the connection, like the
78+
// timezone.
79+
func RegisterReaderHandlerWithConfig(name string, handler func(*Config) io.Reader) {
6980
readerRegisterLock.Lock()
7081
// lazy map init
7182
if readerRegister == nil {
72-
readerRegister = make(map[string]func() io.Reader)
83+
readerRegister = make(map[string]func(*Config) io.Reader)
7384
}
7485

7586
readerRegister[name] = handler
@@ -110,7 +121,7 @@ func (mc *mysqlConn) handleInFileRequest(name string) (err error) {
110121
readerRegisterLock.RUnlock()
111122

112123
if inMap {
113-
rdr = handler()
124+
rdr = handler(mc.cfg.Clone())
114125
if rdr != nil {
115126
if cl, ok := rdr.(io.Closer); ok {
116127
defer deferredClose(&err, cl)

0 commit comments

Comments
 (0)