-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
60 lines (49 loc) · 909 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"cravefeed_backend/Redis"
"cravefeed_backend/Redis/Caching"
"cravefeed_backend/database"
router "cravefeed_backend/routers"
"fmt"
"log"
"net/http"
)
type Config struct {
Port string
}
type Application struct {
Config Config
}
func (app *Application) Serve() error {
port := app.Config.Port
fmt.Printf("Serving app on port %s", port)
srv := &http.Server{
Addr: fmt.Sprintf(":%s", port),
Handler: router.Routes(),
}
return srv.ListenAndServe()
}
func main() {
db, err := database.ConnectDB()
if err != nil {
fmt.Println("Database cannot be connected")
}
Redis.GetClient()
go Caching.UpdateCachePeriodically()
defer Redis.CloseClient()
defer func() {
if db.Client != nil {
db.Client.Disconnect()
}
}()
config := Config{
Port: "3000",
}
app := &Application{
Config: config,
}
err = app.Serve()
if err != nil {
log.Fatal(err)
}
}