db: Handle connection through unix socket
continuous-integration/drone/push Build is passing Details

This commit is contained in:
nemunaire 2021-07-21 10:42:33 +02:00
parent 8e95cec104
commit c2fe14c0d7
1 changed files with 9 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import (
_ "github.com/go-sql-driver/mysql"
"log"
"os"
"strings"
"time"
)
@ -19,11 +20,15 @@ func DSNGenerator() string {
db_db := "fic"
if v, exists := os.LookupEnv("MYSQL_HOST"); exists {
db_host = "tcp(" + v + ":"
if p, exists := os.LookupEnv("MYSQL_PORT"); exists {
db_host += p + ")"
if strings.HasPrefix(v, "/") {
db_host = "unix(" + v + ")"
} else {
db_host += "3306)"
db_host = "tcp(" + v + ":"
if p, exists := os.LookupEnv("MYSQL_PORT"); exists {
db_host += p + ")"
} else {
db_host += "3306)"
}
}
}
if v, exists := os.LookupEnv("MYSQL_PASSWORD"); exists {