-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
37 lines (27 loc) · 804 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
37
package main
import (
"os"
"github.com/joho/godotenv"
"github.com/reisvitt/url-shortener-go/database"
"github.com/reisvitt/url-shortener-go/repository"
"github.com/reisvitt/url-shortener-go/router"
"github.com/reisvitt/url-shortener-go/services"
)
func main() {
err := godotenv.Load()
if err != nil {
panic(err)
}
dbConnection := os.Getenv("DB_CONNECTION")
dbName := os.Getenv("DB_NAME")
// initialize database
database.InitializeMongoDB(dbConnection, dbName)
// create TTL index on 'expires-at' field in 'urls' collection
database.CreateTTLIndex(database.Db.Collection("urls"))
// initialize respository
repo := repository.NewMongoUrlRepository(database.Db)
// initialize service
service := services.NewUrlService(repo)
// initialize router
router.Initialize(service)
}