From e78f20a770fc3e8fcee88f8a3c202ad777f8f6bc Mon Sep 17 00:00:00 2001 From: Ali Golzar Date: Mon, 19 May 2025 16:32:12 +0330 Subject: [PATCH] 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. --- .env.example | 12 ++++++------ config/config.go | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.env.example b/.env.example index 09c24fcf..228fde76 100644 --- a/.env.example +++ b/.env.example @@ -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= \ No newline at end of file +# XUI_DB_HOST=127.0.0.1 +# XUI_DB_PORT=3306 +# XUI_DB_DATABASE=xui +# XUI_DB_USERNAME=root +# XUI_DB_PASSWORD= \ No newline at end of file diff --git a/config/config.go b/config/config.go index 9279fc0d..942de7fb 100644 --- a/config/config.go +++ b/config/config.go @@ -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" {