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
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
launch.json
|
launch.json
|
||||||
.vscode
|
.vscode
|
||||||
.env
|
.env
|
||||||
wakapi
|
wakapi
|
||||||
|
.idea
|
8
main.go
8
main.go
@ -35,9 +35,14 @@ func readConfig() *models.Config {
|
|||||||
dbPassword, valid := os.LookupEnv("WAKAPI_DB_PASSWORD")
|
dbPassword, valid := os.LookupEnv("WAKAPI_DB_PASSWORD")
|
||||||
dbHost, valid := os.LookupEnv("WAKAPI_DB_HOST")
|
dbHost, valid := os.LookupEnv("WAKAPI_DB_HOST")
|
||||||
dbName, valid := os.LookupEnv("WAKAPI_DB_NAME")
|
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 {
|
if !valid {
|
||||||
log.Fatal("Environment variables missing.")
|
log.Fatal("Environment variables missing or invalid.")
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, err := ini.Load("config.ini")
|
cfg, err := ini.Load("config.ini")
|
||||||
@ -63,6 +68,7 @@ func readConfig() *models.Config {
|
|||||||
Port: port,
|
Port: port,
|
||||||
Addr: addr,
|
Addr: addr,
|
||||||
DbHost: dbHost,
|
DbHost: dbHost,
|
||||||
|
DbPort: uint(dbPort),
|
||||||
DbUser: dbUser,
|
DbUser: dbUser,
|
||||||
DbPassword: dbPassword,
|
DbPassword: dbPassword,
|
||||||
DbName: dbName,
|
DbName: dbName,
|
||||||
|
@ -4,6 +4,7 @@ type Config struct {
|
|||||||
Port int
|
Port int
|
||||||
Addr string
|
Addr string
|
||||||
DbHost string
|
DbHost string
|
||||||
|
DbPort uint
|
||||||
DbUser string
|
DbUser string
|
||||||
DbPassword string
|
DbPassword string
|
||||||
DbName string
|
DbName string
|
||||||
|
@ -3,6 +3,7 @@ package utils
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -34,6 +35,8 @@ func MakeConnectionString(config *models.Config) string {
|
|||||||
str.WriteString(config.DbPassword)
|
str.WriteString(config.DbPassword)
|
||||||
str.WriteString("@tcp(")
|
str.WriteString("@tcp(")
|
||||||
str.WriteString(config.DbHost)
|
str.WriteString(config.DbHost)
|
||||||
|
str.WriteString(":")
|
||||||
|
str.WriteString(strconv.Itoa(int(config.DbPort)))
|
||||||
str.WriteString(")/")
|
str.WriteString(")/")
|
||||||
str.WriteString(config.DbName)
|
str.WriteString(config.DbName)
|
||||||
str.WriteString("?charset=utf8&parseTime=true&loc=")
|
str.WriteString("?charset=utf8&parseTime=true&loc=")
|
||||||
|
Loading…
Reference in New Issue
Block a user