refactor: prefix env variables of database with XUI_ to support direct environment usage without .env file

All database configuration environment variables now start with the XUI_ prefix to avoid conflicts and allow configuration via system-level environment variables, not just the .env file.
This commit is contained in:
Ali Golzar 2025-05-19 16:32:12 +03:30
parent 4d50320bc1
commit e78f20a770
2 changed files with 12 additions and 12 deletions

View file

@ -1,8 +1,8 @@
DB_CONNECTION=sqlite
XUI_DB_CONNECTION=sqlite
# If DB connection is "mysql"
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=xui
# DB_USERNAME=root
# DB_PASSWORD=
# XUI_DB_HOST=127.0.0.1
# XUI_DB_PORT=3306
# XUI_DB_DATABASE=xui
# XUI_DB_USERNAME=root
# XUI_DB_PASSWORD=

View file

@ -76,12 +76,12 @@ type DatabaseConfig struct {
// GetDatabaseConfig returns the database configuration from environment variables
func GetDatabaseConfig() (*DatabaseConfig, error) {
config := &DatabaseConfig{
Connection: strings.ToLower(os.Getenv("DB_CONNECTION")),
Host: os.Getenv("DB_HOST"),
Port: os.Getenv("DB_PORT"),
Database: os.Getenv("DB_DATABASE"),
Username: os.Getenv("DB_USERNAME"),
Password: os.Getenv("DB_PASSWORD"),
Connection: strings.ToLower(os.Getenv("XUI_DB_CONNECTION")),
Host: os.Getenv("XUI_DB_HOST"),
Port: os.Getenv("XUI_DB_PORT"),
Database: os.Getenv("XUI_DB_DATABASE"),
Username: os.Getenv("XUI_DB_USERNAME"),
Password: os.Getenv("XUI_DB_PASSWORD"),
}
if config.Connection == "mysql" {