-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
45 lines (35 loc) · 938 Bytes
/
main.go
File metadata and controls
45 lines (35 loc) · 938 Bytes
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
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/PratikforCoding/BusoFact.git/controllers"
"github.com/PratikforCoding/BusoFact.git/database"
"github.com/PratikforCoding/BusoFact.git/router"
"github.com/joho/godotenv"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
mongouri := os.Getenv("connectlink")
jwtSecret := os.Getenv("JWT_SECRET")
busCol, usrCol, err := database.CreateDB(mongouri)
if err != nil {
log.Fatal("Didn't create connection to mongodb")
}
defer database.CloseDB()
apicfg := controller.NewAPIConfig(busCol, usrCol, jwtSecret)
fmt.Println("MongoDB API")
r := router.Router(apicfg)
corsMux := middlewareCors(r)
server := &http.Server {
Addr: ":8080",
Handler: corsMux,
}
log.Println("Server is getting started at port: 8080 ....")
log.Fatal(server.ListenAndServe())
log.Println("Server is runnig at port: 8080 ....")
}