@@ -20,15 +20,17 @@ import (
20
20
"time"
21
21
)
22
22
23
+ // Registry for custom tls.Configs
23
24
var (
24
25
tlsConfigLock sync.RWMutex
25
- tlsConfigRegister map [string ]* tls.Config // Register for custom tls.Configs
26
+ tlsConfigRegistry map [string ]* tls.Config
26
27
)
27
28
28
29
// RegisterTLSConfig registers a custom tls.Config to be used with sql.Open.
29
30
// Use the key as a value in the DSN where tls=value.
30
31
//
31
- // Note: The tls.Config provided to needs to be exclusively owned by the driver after registering.
32
+ // Note: The provided tls.Config is exclusively owned by the driver after
33
+ // registering it.
32
34
//
33
35
// rootCertPool := x509.NewCertPool()
34
36
// pem, err := ioutil.ReadFile("/path/ca-cert.pem")
@@ -56,27 +58,27 @@ func RegisterTLSConfig(key string, config *tls.Config) error {
56
58
}
57
59
58
60
tlsConfigLock .Lock ()
59
- if tlsConfigRegister == nil {
60
- tlsConfigRegister = make (map [string ]* tls.Config )
61
+ if tlsConfigRegistry == nil {
62
+ tlsConfigRegistry = make (map [string ]* tls.Config )
61
63
}
62
64
63
- tlsConfigRegister [key ] = config
65
+ tlsConfigRegistry [key ] = config
64
66
tlsConfigLock .Unlock ()
65
67
return nil
66
68
}
67
69
68
70
// DeregisterTLSConfig removes the tls.Config associated with key.
69
71
func DeregisterTLSConfig (key string ) {
70
72
tlsConfigLock .Lock ()
71
- if tlsConfigRegister != nil {
72
- delete (tlsConfigRegister , key )
73
+ if tlsConfigRegistry != nil {
74
+ delete (tlsConfigRegistry , key )
73
75
}
74
76
tlsConfigLock .Unlock ()
75
77
}
76
78
77
79
func getTLSConfigClone (key string ) (config * tls.Config ) {
78
80
tlsConfigLock .RLock ()
79
- if v , ok := tlsConfigRegister [key ]; ok {
81
+ if v , ok := tlsConfigRegistry [key ]; ok {
80
82
config = cloneTLSConfig (v )
81
83
}
82
84
tlsConfigLock .RUnlock ()
0 commit comments