add .env.example file with configuration settings, refactor environment variable access methods

This commit is contained in:
2025-07-22 09:31:58 +08:00
parent 00c28fea9c
commit 08872ea015
7 changed files with 56 additions and 17 deletions

View File

@ -73,12 +73,12 @@ func (e *emailUtils) SendEmail(emailConfig *EmailConfig, target, subject, conten
func (e *emailUtils) GetEmailConfigFromEnv() *EmailConfig {
return &EmailConfig{
Enable: Env.GetenvAsBool("EMAIL_ENABLE", false),
Enable: Env.GetAsBool("EMAIL_ENABLE", false),
Username: Env.Get("EMAIL_USERNAME", ""),
Address: Env.Get("EMAIL_ADDRESS", ""),
Host: Env.Get("EMAIL_HOST", "smtp.example.com"),
Port: Env.GetenvAsInt("EMAIL_PORT", 587),
Port: Env.GetAsInt("EMAIL_PORT", 587),
Password: Env.Get("EMAIL_PASSWORD", ""),
SSL: Env.GetenvAsBool("EMAIL_SSL", true),
SSL: Env.GetAsBool("EMAIL_SSL", true),
}
}

View File

@ -30,7 +30,7 @@ func (e *envUtils) Get(key string, defaultValue ...string) string {
return value
}
func (e *envUtils) GetenvAsInt(key string, defaultValue ...int) int {
func (e *envUtils) GetAsInt(key string, defaultValue ...int) int {
value := os.Getenv(key)
if value == "" && len(defaultValue) > 0 {
return defaultValue[0]
@ -42,7 +42,7 @@ func (e *envUtils) GetenvAsInt(key string, defaultValue ...int) int {
return intValue
}
func (e *envUtils) GetenvAsBool(key string, defaultValue ...bool) bool {
func (e *envUtils) GetAsBool(key string, defaultValue ...bool) bool {
value := os.Getenv(key)
if value == "" && len(defaultValue) > 0 {
return defaultValue[0]