MCPcopy
hub / github.com/go-sql-driver/mysql / RegisterTLSConfig

Function RegisterTLSConfig

utils.go:57–70  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

55// })
56// db, err := sql.Open("mysql", "user@tcp(localhost:3306)/test?tls=custom")
57func 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.
73func DeregisterTLSConfig(key string) {

Callers 4

TestDSNWithCustomTLSFunction · 0.85
TestNormalizeTLSConfigFunction · 0.85
TestTLSFunction · 0.85

Calls 3

readBoolFunction · 0.85
LockMethod · 0.80
UnlockMethod · 0.80

Tested by 4

TestDSNWithCustomTLSFunction · 0.68
TestNormalizeTLSConfigFunction · 0.68
TestTLSFunction · 0.68