-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
55 lines (48 loc) · 1.02 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
54
55
package main
import (
"context"
"log"
"os"
"redis/cache"
"redis/controller"
"redis/mongodb"
"redis/repository"
"redis/service"
"github.com/joho/godotenv"
"github.com/labstack/echo"
)
func init() {
err := godotenv.Load(".config/.env")
if err != nil {
log.Panicln(err)
}
}
func main() {
const (
cacheDB = 1
cacheExpire = 1
)
var err error
mongoDB, err := mongodb.NewMongoDB()
if err != nil {
log.Panicln(err)
}
defer mongoDB.CloseConnection(context.Background())
serverRedisCache := cache.NewRedisCache(
os.Getenv("CACHE_HOST"),
os.Getenv("CACHE_PASSWORD"),
cacheDB,
cacheExpire,
)
serverRepository := repository.NewRepository(mongoDB)
serverService := service.NewService(serverRepository, serverRedisCache)
serverController := controller.NewController(serverService)
server := echo.New()
server.HideBanner = true
server.GET("/humans", serverController.GetHumans)
server.GET("/humans/:id", serverController.GetHuman)
err = server.Start(":8080")
if err != nil {
log.Panicln(err)
}
}