Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettladley committed Feb 25, 2024
1 parent 646cc4d commit c1a9c3a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions backend/src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const (
EnvironmentProduction Environment = "production"
)

func GetConfiguration(path string) (*Settings, error) {
func GetConfiguration(path string, useDevDotEnv bool) (*Settings, error) {
var environment Environment
if env := os.Getenv("APP_ENVIRONMENT"); env != "" {
environment = Environment(env)
Expand All @@ -66,7 +66,7 @@ func GetConfiguration(path string) (*Settings, error) {
v.AddConfigPath(path)

if environment == EnvironmentLocal {
return readLocal(v, path)
return readLocal(v, path, useDevDotEnv)
} else {
return readProd(v)
}
Expand Down
9 changes: 7 additions & 2 deletions backend/src/config/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/spf13/viper"
)

func readLocal(v *viper.Viper, path string) (*Settings, error) {
func readLocal(v *viper.Viper, path string, useDevDotEnv bool) (*Settings, error) {
var intermediateSettings intermediateSettings

env := string(EnvironmentLocal)
Expand All @@ -27,7 +27,12 @@ func readLocal(v *viper.Viper, path string) (*Settings, error) {
return nil, fmt.Errorf("failed to convert intermediate settings into final settings: %w", err)
}

err = godotenv.Load(fmt.Sprintf("%s/.env.template", path))
if useDevDotEnv {
err = godotenv.Load(fmt.Sprintf("%s/.env.dev", path))
} else {
err = godotenv.Load(fmt.Sprintf("%s/.env.template", path))
}

if err != nil {
return nil, fmt.Errorf("failed to load %s/.env.template: %w", path, err)
}
Expand Down
3 changes: 2 additions & 1 deletion backend/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import (
func main() {
onlyMigrate := flag.Bool("only-migrate", false, "Specify if you want to only perform the database migration")
configPath := flag.String("config", filepath.Join("..", "..", "config"), "Specify the path to the config directory")
useDevDotEnv := flag.Bool("use-dev-dot-env", false, "Specify if you want to use the .env.dev file")

flag.Parse()

config, err := config.GetConfiguration(*configPath)
config, err := config.GetConfiguration(*configPath, *useDevDotEnv)
if err != nil {
panic(fmt.Sprintf("Error getting configuration: %s", err.Error()))
}
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/api/helpers/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func spawnApp() (*TestApp, error) {
return nil, err
}

configuration, err := config.GetConfiguration(filepath.Join("..", "..", "..", "config"))
configuration, err := config.GetConfiguration(filepath.Join("..", "..", "..", "config"), false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ var (
ROOT_DIR, _ = utils.GetRootDir()
FRONTEND_DIR = filepath.Join(ROOT_DIR, "/frontend")
BACKEND_DIR = filepath.Join(ROOT_DIR, "/backend/src")
CONFIG, _ = config.GetConfiguration(filepath.Join(ROOT_DIR, "/config"))
CONFIG, _ = config.GetConfiguration(filepath.Join(ROOT_DIR, "/config"), false)
MIGRATION_FILE = filepath.Join(BACKEND_DIR, "/migrations/data.sql")
)

0 comments on commit c1a9c3a

Please sign in to comment.