Improve email config error to name the missing variable(s)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
48e7acab83
commit
eb930b0794
1 changed files with 16 additions and 2 deletions
|
|
@ -3,6 +3,7 @@ package email
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/emersion/go-imap/client"
|
||||
"github.com/joho/godotenv"
|
||||
|
|
@ -44,8 +45,21 @@ func NewConfigFromEnv() (*Config, error) {
|
|||
fetchServer = os.Getenv("IMAP_SERVER")
|
||||
sendServer = os.Getenv("SMTP_SERVER")
|
||||
|
||||
if len(username) == 0 || len(password) == 0 || len(fetchServer) == 0 || len(sendServer) == 0 {
|
||||
return nil, fmt.Errorf("missing configuration variables")
|
||||
var missing []string
|
||||
if len(username) == 0 {
|
||||
missing = append(missing, "EMAIL_USERNAME")
|
||||
}
|
||||
if len(password) == 0 {
|
||||
missing = append(missing, "EMAIL_PASSWORD")
|
||||
}
|
||||
if len(fetchServer) == 0 {
|
||||
missing = append(missing, "IMAP_SERVER")
|
||||
}
|
||||
if len(sendServer) == 0 {
|
||||
missing = append(missing, "SMTP_SERVER")
|
||||
}
|
||||
if len(missing) > 0 {
|
||||
return nil, fmt.Errorf("missing configuration variables: %s", strings.Join(missing, ", "))
|
||||
}
|
||||
|
||||
return NewConfig(username, password, fetchServer, sendServer), nil
|
||||
|
|
|
|||
Loading…
Reference in a new issue