-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
36 lines (30 loc) · 929 Bytes
/
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
package main
import (
"log"
"os"
"github.com/joho/godotenv"
"github.com/sggts04/urlshortener-go/data"
"github.com/sggts04/urlshortener-go/handlers"
"github.com/sggts04/urlshortener-go/services"
)
func main() {
// Load ENV Vars
if err := godotenv.Load(); err != nil {
log.Fatal("Error loading .env file")
}
PORT := os.Getenv("PORT")
MYSQL_USER := os.Getenv("MYSQL_USER")
MYSQL_PASS := os.Getenv("MYSQL_PASS")
MYSQL_ADDR := os.Getenv("MYSQL_ADDR")
MYSQL_DB := os.Getenv("MYSQL_DB")
// Init Database Connection
db, err := data.InitDatabaseConnection(MYSQL_USER, MYSQL_PASS, MYSQL_ADDR, MYSQL_DB)
if err != nil {
log.Fatal("Coudn't connect to database")
}
// Initialize Repository, Handler and Service (Using Dependency Injection)
repo := data.NewRepository(db)
handler := handlers.NewURLShorteningHandler(repo)
service := services.NewURLShorteningService(handler)
service.Run("localhost:" + PORT)
}