Socialify

Folder ..

Viewing config.go
32 lines (25 loc) • 546.0 B

 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
package config

import (
	"log/slog"
	"os"

	"github.com/joho/godotenv"
)

var (
	Port                         string
	DSN                          string
	ClearAndResetDatabaseOnStart bool
)

func init() {
	if err := godotenv.Load(); err != nil {
		slog.Error("Failed to load environment variables from .env file")
	}

	Port = os.Getenv("PORT")
	if Port == "" {
		Port = "3000"
	}

	DSN = os.Getenv("DSN")
	if DSN == "" {
		slog.Error("DSN not set")
	}

	ClearAndResetDatabaseOnStart = os.Getenv("CLEAR_AND_RESET_DATABASE_ON_START") == "true"
}