mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
Add ability to configure database port.
This commit is contained in:
parent
9e726028c3
commit
caacea3f63
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@ launch.json
|
||||
.vscode
|
||||
.env
|
||||
wakapi
|
||||
.idea
|
8
main.go
8
main.go
@ -35,9 +35,14 @@ func readConfig() *models.Config {
|
||||
dbPassword, valid := os.LookupEnv("WAKAPI_DB_PASSWORD")
|
||||
dbHost, valid := os.LookupEnv("WAKAPI_DB_HOST")
|
||||
dbName, valid := os.LookupEnv("WAKAPI_DB_NAME")
|
||||
dbPortStr, valid := os.LookupEnv("WAKAPI_DB_PORT")
|
||||
dbPort, err := strconv.Atoi(dbPortStr)
|
||||
if err != nil {
|
||||
dbPort = 3306
|
||||
}
|
||||
|
||||
if !valid {
|
||||
log.Fatal("Environment variables missing.")
|
||||
log.Fatal("Environment variables missing or invalid.")
|
||||
}
|
||||
|
||||
cfg, err := ini.Load("config.ini")
|
||||
@ -63,6 +68,7 @@ func readConfig() *models.Config {
|
||||
Port: port,
|
||||
Addr: addr,
|
||||
DbHost: dbHost,
|
||||
DbPort: uint(dbPort),
|
||||
DbUser: dbUser,
|
||||
DbPassword: dbPassword,
|
||||
DbName: dbName,
|
||||
|
@ -4,6 +4,7 @@ type Config struct {
|
||||
Port int
|
||||
Addr string
|
||||
DbHost string
|
||||
DbPort uint
|
||||
DbUser string
|
||||
DbPassword string
|
||||
DbName string
|
||||
|
@ -3,6 +3,7 @@ package utils
|
||||
import (
|
||||
"errors"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -34,6 +35,8 @@ func MakeConnectionString(config *models.Config) string {
|
||||
str.WriteString(config.DbPassword)
|
||||
str.WriteString("@tcp(")
|
||||
str.WriteString(config.DbHost)
|
||||
str.WriteString(":")
|
||||
str.WriteString(strconv.Itoa(int(config.DbPort)))
|
||||
str.WriteString(")/")
|
||||
str.WriteString(config.DbName)
|
||||
str.WriteString("?charset=utf8&parseTime=true&loc=")
|
||||
|
Loading…
Reference in New Issue
Block a user