db: Handle connection through unix socket
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
8e95cec104
commit
c2fe14c0d7
1 changed files with 9 additions and 4 deletions
13
libfic/db.go
13
libfic/db.go
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue