-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (41 loc) · 1.06 KB
/
main.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// main.go
package main
import (
"log"
"os"
"github.com/joho/godotenv"
"github.com/xceejay/rest-api-starter/handlers"
)
const (
ENVIRONMENT = "DEVELOPMENT"
)
func main() {
server := handlers.Server{}
log.Println("Configuration loaded:", ENVIRONMENT)
server.Initialize(LoadDBConfig())
log.Println("Starting server on http://127.0.0.1:7070")
server.Run(":7070")
}
func LoadDBConfig() (string, string, string, string) {
if ENVIRONMENT == "DEVELOPMENT" {
err := godotenv.Load("config/.env.development")
if err != nil {
log.Fatal("Error loading .env file")
}
username := os.Getenv("USERNAME")
password := os.Getenv("PASSWORD")
hostname := os.Getenv("HOSTNAME")
dbname := os.Getenv("DBNAME")
return username, password, hostname, dbname
} else {
err := godotenv.Load("config/.env.production")
if err != nil {
log.Fatal("Error loading .env file")
}
username := os.Getenv("USERNAME")
password := os.Getenv("PASSWORD")
hostname := os.Getenv("HOSTNAME")
dbname := os.Getenv("DBNAME")
return username, password, hostname, dbname
}
}