Переглянути джерело

lazy init tlsConfigRegister

Julien Schmidt 10 роки тому
батько
коміт
ca130be66a
1 змінених файлів з 7 додано та 5 видалено
  1. 7 5
      utils.go

+ 7 - 5
utils.go

@@ -23,10 +23,6 @@ var (
 	tlsConfigRegister map[string]*tls.Config // Register for custom tls.Configs
 )
 
-func init() {
-	tlsConfigRegister = make(map[string]*tls.Config)
-}
-
 // RegisterTLSConfig registers a custom tls.Config to be used with sql.Open.
 // Use the key as a value in the DSN where tls=value.
 //
@@ -55,13 +51,19 @@ func RegisterTLSConfig(key string, config *tls.Config) error {
 		return fmt.Errorf("Key '%s' is reserved", key)
 	}
 
+	if tlsConfigRegister == nil {
+		tlsConfigRegister = make(map[string]*tls.Config)
+	}
+
 	tlsConfigRegister[key] = config
 	return nil
 }
 
 // DeregisterTLSConfig removes the tls.Config associated with key.
 func DeregisterTLSConfig(key string) {
-	delete(tlsConfigRegister, key)
+	if tlsConfigRegister != nil {
+		delete(tlsConfigRegister, key)
+	}
 }
 
 // Returns the bool value of the input.