aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/config.go
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-07-28 19:41:04 +0900
committernsfisis <nsfisis@gmail.com>2024-07-28 19:41:04 +0900
commit7bd55ee264f7eefda6c1f71865a2c6287d7e20fa (patch)
tree269110eeb9250da7cc0f80a948ea647f69ca9be5 /backend/config.go
parent0b09103e894a5f7c6865e5bdd20992457cec3c9f (diff)
downloadphperkaigi-2025-albatross-7bd55ee264f7eefda6c1f71865a2c6287d7e20fa.tar.gz
phperkaigi-2025-albatross-7bd55ee264f7eefda6c1f71865a2c6287d7e20fa.tar.zst
phperkaigi-2025-albatross-7bd55ee264f7eefda6c1f71865a2c6287d7e20fa.zip
refactor(backend): move config-related code to config.go
Diffstat (limited to 'backend/config.go')
-rw-r--r--backend/config.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/backend/config.go b/backend/config.go
new file mode 100644
index 0000000..c083542
--- /dev/null
+++ b/backend/config.go
@@ -0,0 +1,44 @@
+package main
+
+import (
+ "fmt"
+ "os"
+)
+
+type Config struct {
+ dbHost string
+ dbPort string
+ dbUser string
+ dbPassword string
+ dbName string
+}
+
+func NewConfigFromEnv() (*Config, error) {
+ dbHost, exists := os.LookupEnv("ALBATROSS_DB_HOST")
+ if !exists {
+ return nil, fmt.Errorf("ALBATROSS_DB_HOST not set")
+ }
+ dbPort, exists := os.LookupEnv("ALBATROSS_DB_PORT")
+ if !exists {
+ return nil, fmt.Errorf("ALBATROSS_DB_PORT not set")
+ }
+ dbUser, exists := os.LookupEnv("ALBATROSS_DB_USER")
+ if !exists {
+ return nil, fmt.Errorf("ALBATROSS_DB_USER not set")
+ }
+ dbPassword, exists := os.LookupEnv("ALBATROSS_DB_PASSWORD")
+ if !exists {
+ return nil, fmt.Errorf("ALBATROSS_DB_PASSWORD not set")
+ }
+ dbName, exists := os.LookupEnv("ALBATROSS_DB_NAME")
+ if !exists {
+ return nil, fmt.Errorf("ALBATROSS_DB_NAME not set")
+ }
+ return &Config{
+ dbHost: dbHost,
+ dbPort: dbPort,
+ dbUser: dbUser,
+ dbPassword: dbPassword,
+ dbName: dbName,
+ }, nil
+}