db: Handle connection through unix socket
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nemunaire 2021-07-21 10:42:33 +02:00
parent 8e95cec104
commit c2fe14c0d7

View File

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