clear 'tls=value' from original dsn on mysql

pull/180/head
Songmu 2020-04-15 22:24:40 +09:00
parent c6b57c23c5
commit 522080545b
1 changed files with 6 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import (
"fmt"
"io/ioutil"
"log"
"regexp"
"github.com/go-sql-driver/mysql"
_ "github.com/ziutek/mymysql/godrv"
@ -36,7 +37,12 @@ func normalizeDBString(driver string, str string, certfile string) string {
const tlsConfigKey = "custom"
var tlsReg = regexp.MustCompile(`(\?|&)tls=[^&]*(?:&|$)`)
func normalizeMySQLDSN(dsn string, tls bool) (string, error) {
// If we are sharing a DSN in a different environment, it may contain a TLS
// setting key with a value name that is not "custom," so clear it.
dsn = tlsReg.ReplaceAllString(dsn, `$1`)
config, err := mysql.ParseDSN(dsn)
if err != nil {
return "", err