Skip to content

Commit ca130be

Browse files
committed
lazy init tlsConfigRegister
1 parent 618fbd9 commit ca130be

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

utils.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ var (
2323
tlsConfigRegister map[string]*tls.Config // Register for custom tls.Configs
2424
)
2525

26-
func init() {
27-
tlsConfigRegister = make(map[string]*tls.Config)
28-
}
29-
3026
// RegisterTLSConfig registers a custom tls.Config to be used with sql.Open.
3127
// Use the key as a value in the DSN where tls=value.
3228
//
@@ -55,13 +51,19 @@ func RegisterTLSConfig(key string, config *tls.Config) error {
5551
return fmt.Errorf("Key '%s' is reserved", key)
5652
}
5753

54+
if tlsConfigRegister == nil {
55+
tlsConfigRegister = make(map[string]*tls.Config)
56+
}
57+
5858
tlsConfigRegister[key] = config
5959
return nil
6060
}
6161

6262
// DeregisterTLSConfig removes the tls.Config associated with key.
6363
func DeregisterTLSConfig(key string) {
64-
delete(tlsConfigRegister, key)
64+
if tlsConfigRegister != nil {
65+
delete(tlsConfigRegister, key)
66+
}
6567
}
6668

6769
// Returns the bool value of the input.

0 commit comments

Comments
 (0)