fixed issues with first-time setup, added config.db.port

This commit is contained in:
ari melody 2025-01-21 14:12:21 +00:00
parent 7bea6b548e
commit 3d674515ce
Signed by: ari
GPG key ID: CF99829C92678188
4 changed files with 26 additions and 12 deletions

View file

@ -13,6 +13,7 @@ import (
type (
dbConfig struct {
Host string `toml:"host"`
Port int64 `toml:"port"`
Name string `toml:"name"`
User string `toml:"user"`
Pass string `toml:"pass"`
@ -42,6 +43,12 @@ var Config = func() config {
config := config{
BaseUrl: "https://arimelody.me",
Port: 8080,
DB: dbConfig{
Host: "127.0.0.1",
Port: 5432,
User: "arimelody",
Name: "arimelody",
},
}
data, err := os.ReadFile(configFile)
@ -80,6 +87,10 @@ func handleConfigOverrides(config *config) error {
if env, has := os.LookupEnv("ARIMELODY_DATA_DIR"); has { config.DataDirectory = env }
if env, has := os.LookupEnv("ARIMELODY_DB_HOST"); has { config.DB.Host = env }
if env, has := os.LookupEnv("ARIMELODY_DB_PORT"); has {
config.DB.Port, err = strconv.ParseInt(env, 10, 0)
if err != nil { return errors.New("ARIMELODY_DB_PORT: " + err.Error()) }
}
if env, has := os.LookupEnv("ARIMELODY_DB_NAME"); has { config.DB.Name = env }
if env, has := os.LookupEnv("ARIMELODY_DB_USER"); has { config.DB.User = env }
if env, has := os.LookupEnv("ARIMELODY_DB_PASS"); has { config.DB.Pass = env }