RegisterTLSConfig registers a custom tls.Config to be used with sql.Open. Use the key as a value in the DSN where tls=value. Note: The provided tls.Config is exclusively owned by the driver after registering it. rootCertPool := x509.NewCertPool() pem, err := os.ReadFile("/path/ca-cert.pem") if
(key string, config *tls.Config)
| 55 | // }) |
| 56 | // db, err := sql.Open("mysql", "user@tcp(localhost:3306)/test?tls=custom") |
| 57 | func RegisterTLSConfig(key string, config *tls.Config) error { |
| 58 | if _, isBool := readBool(key); isBool || strings.ToLower(key) == "skip-verify" || strings.ToLower(key) == "preferred" { |
| 59 | return fmt.Errorf("key '%s' is reserved", key) |
| 60 | } |
| 61 | |
| 62 | tlsConfigLock.Lock() |
| 63 | if tlsConfigRegistry == nil { |
| 64 | tlsConfigRegistry = make(map[string]*tls.Config) |
| 65 | } |
| 66 | |
| 67 | tlsConfigRegistry[key] = config |
| 68 | tlsConfigLock.Unlock() |
| 69 | return nil |
| 70 | } |
| 71 | |
| 72 | // DeregisterTLSConfig removes the tls.Config associated with key. |
| 73 | func DeregisterTLSConfig(key string) { |