diff options
Diffstat (limited to 'config')
| -rw-r--r-- | config/config.go | 22 | ||||
| -rw-r--r-- | config/env.go | 8 |
2 files changed, 30 insertions, 0 deletions
diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..85f947c --- /dev/null +++ b/config/config.go @@ -0,0 +1,22 @@ +package config + +import ( + "cafe/utils/env" + "log" + + "github.com/joho/godotenv" +) + +var ( + Server server +) + +func init() { + if err := godotenv.Load(); err != nil { + log.Println("No .env file found, using environment variables") + } + + if err := env.Parse(&Server); err != nil { + log.Fatalf("Failed to parse ServerConfig: %v", err) + } +} diff --git a/config/env.go b/config/env.go new file mode 100644 index 0000000..bdac2b4 --- /dev/null +++ b/config/env.go @@ -0,0 +1,8 @@ +package config + +type server struct { + Host string `env:"SERVER_HOST" default:"localhost"` + Port int `env:"SERVER_PORT" default:"8080"` + AppSecret string `env:"APP_SECRET" default:"mysecret"` + DevMode bool `env:"DEV_MODE" default:"true"` +} |
