Skip to content

refactor(config): split config.go and rename fields to camelCase#157

Open
Gautam7352 wants to merge 1 commit into
devfrom
pr/config-validation
Open

refactor(config): split config.go and rename fields to camelCase#157
Gautam7352 wants to merge 1 commit into
devfrom
pr/config-validation

Conversation

@Gautam7352

Copy link
Copy Markdown
Contributor
  • Extract postgresPortFromEnv, loadEnvFile, findEnvFile into loader.go
  • Extract validateDatabaseConfig into validation.go
  • Rename AppConfig fields from SCREAMING_SNAKE to camelCase (PostgresHost etc.)
  • Skip .env loading in production (APP_ENV=production)
  • Harden JWT_SECRET: fatal in production, warn with safe default in dev
  • Update database/db.go to use renamed AppConfig fields

- Extract postgresPortFromEnv, loadEnvFile, findEnvFile into loader.go
- Extract validateDatabaseConfig into validation.go
- Rename AppConfig fields from SCREAMING_SNAKE to camelCase (PostgresHost etc.)
- Skip .env loading in production (APP_ENV=production)
- Harden JWT_SECRET: fatal in production, warn with safe default in dev
- Update database/db.go to use renamed AppConfig fields
Comment on lines +9 to +12
PostgresPassword string
PostgresUser string
PostgresDB string
PostgresHost string

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is camel case related to some go conventions? Usually constants are defined as snake case capital letters

"github.com/joho/godotenv"
)

func loadEnvFile() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not be using files for environment variable? Why is this function present?

return "", os.ErrNotExist
}

func postgresPortFromEnv() (int, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not get the point of this function. Why do we need a function to get port of postgres?

func validateDatabaseConfig(cfg AppConfig) error {
missing := make([]string, 0, 4)

if cfg.PostgresUser == "" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are if statements the only thing we can do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants