@@ -44,16 +44,11 @@ func LoadEnvironmentVariables() {
4444
4545func loadConfigs () error {
4646 if os .Getenv (appEnv ) == "development" {
47- log .Println ("Environment: Loading `" + envFileDevelopment + "`" )
48- if err := godotenv .Load (envFileDevelopment ); err != nil {
49- log .Printf ("Environment: Could not load `%s`: %v" , envFileDevelopment , err )
50- }
51- return nil
47+ return loadOptionalEnvironmentFile (envFileDevelopment )
5248 }
5349
54- log .Println ("Environment: Loading `" + envFileProduction + "`" )
55- if err := godotenv .Load (envFileProduction ); err != nil {
56- log .Printf ("Environment: Could not load `%s`: %v" , envFileProduction , err )
50+ if err := loadOptionalEnvironmentFile (envFileProduction ); err != nil {
51+ return err
5752 }
5853
5954 if os .Getenv (FrontendDisabled ) == "" {
@@ -67,6 +62,22 @@ func loadConfigs() error {
6762 return nil
6863}
6964
65+ func loadOptionalEnvironmentFile (fileName string ) error {
66+ if _ , err := os .Stat (fileName ); errors .Is (err , os .ErrNotExist ) {
67+ log .Printf ("Environment: `%s` not found, continuing with system environment" , fileName )
68+ return nil
69+ } else if err != nil {
70+ return err
71+ }
72+
73+ log .Println ("Environment: Loading `" + fileName + "`" )
74+ if err := godotenv .Load (fileName ); err != nil {
75+ return err
76+ }
77+
78+ return nil
79+ }
80+
7081func GetFrontendPath () string {
7182 frontendPath := os .Getenv (frontendPath )
7283 if frontendPath == "" {
0 commit comments