forked from palembang-digital/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
30 lines (24 loc) · 970 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package main
import "github.com/kelseyhightower/envconfig"
// Config stores the application configurations.
type Config struct {
Port string `envconfig:"PORT" default:"8080"`
UIBuildPath string `envconfig:"UI_BUILD_PATH" default:"ui/build"`
AdminUsername string `envconfig:"ADMIN_USERNAME" default:"admin"`
AdminPassword string `envconfig:"ADMIN_PASSWORD" default:"admin"`
Database DatabaseConfig
}
// DatabaseConfig stores database configurations.
type DatabaseConfig struct {
URL string `envconfig:"DATABASE_URL" required:"true"`
Driver string `envconfig:"DATABASE_DRIVER" default:"postgres"`
MigrationsPath string `envconfig:"DATABASE_MIGRATIONS_PATH" required:"true" default:"file://migrations/postgresql"`
}
// ReadConfig populates configurations from environment variables.
func ReadConfig() (Config, error) {
var cfg Config
if err := envconfig.Process("", &cfg); err != nil {
return Config{}, err
}
return cfg, nil
}