aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/config.go
blob: 99a6d547832640b1f1c31a63f66c31ad20f19116 (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main

import (
	"fmt"
	"os"
)

type Config struct {
	dbHost     string
	dbPort     string
	dbUser     string
	dbPassword string
	dbName     string
	isLocal    bool
}

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")
	}
	isLocalStr, exists := os.LookupEnv("ALBATROSS_IS_LOCAL")
	isLocal := exists && isLocalStr == "1"
	return &Config{
		dbHost:     dbHost,
		dbPort:     dbPort,
		dbUser:     dbUser,
		dbPassword: dbPassword,
		dbName:     dbName,
		isLocal:    isLocal,
	}, nil
}