-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
215cd15
commit c40a448
Showing
1 changed file
with
10 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,27 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/caarlos0/env" | ||
"fmt" | ||
|
||
"github.com/caarlos0/env/v11" | ||
"github.com/joho/godotenv" | ||
) | ||
|
||
func LoadEnv(path ...string) { | ||
if path != nil { | ||
func LoadEnv(path ...string) error { | ||
if len(path) > 0 { | ||
if err := godotenv.Load(path...); err != nil { | ||
panic(err) | ||
return fmt.Errorf("failed to load env: %w", err) | ||
} | ||
} | ||
|
||
config := &config{} | ||
|
||
if err := env.Parse(&config.Server); err != nil { | ||
panic(err) | ||
} | ||
|
||
if err := env.Parse(&config.NewRelic); err != nil { | ||
panic(err) | ||
return err | ||
} | ||
|
||
// ... configに構造体を追加したら env.Parseする | ||
Config = config | ||
|
||
return nil | ||
} |