-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
64 lines (50 loc) 路 1.63 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
56
57
58
59
60
61
62
63
64
package main
import (
"context"
"github.com/psmarcin/youtubegoespodcast/internal/adapters"
application "github.com/psmarcin/youtubegoespodcast/internal/app"
"github.com/psmarcin/youtubegoespodcast/internal/config"
"github.com/psmarcin/youtubegoespodcast/internal/logger"
"github.com/psmarcin/youtubegoespodcast/internal/ports"
"github.com/sirupsen/logrus"
)
var l = logrus.WithField("source", "cmd")
func main() {
// Config
config.Init()
ctx := context.Background()
traceFlusher := config.InitTracer(config.Cfg)
defer func() {
err := traceFlusher(ctx)
l.WithError(err).Fatalf("can't flush traces")
}()
// Logger
logger.Setup()
// Cache
cacheRepository, err := adapters.NewCacheRepository()
if err != nil {
l.WithError(err).Fatalf("can't create cache repository")
}
cacheService := application.NewCacheService(&cacheRepository)
// YouTube
yt, err := adapters.NewYouTube()
if err != nil {
l.WithError(err).Fatalf("can't connect to youtube service")
}
youTubeAPIRepository := adapters.NewYouTubeAPIRepository(yt)
youTubeRepository, err := adapters.NewYouTubeRepository()
if err != nil {
l.WithError(err).Fatalf("can't create youtube request repository")
}
youTubeService := application.NewYouTubeService(youTubeRepository, youTubeAPIRepository, cacheService)
// YTDL
// ytdlRepository := adapters.NewYTDLRepository()
// ytdlService := application.NewYTDLService(ytdlRepository)
// Video
fileService := application.NewFileService()
// API
fiberServer := ports.CreateHTTPServer()
h := ports.NewHTTPServer(fiberServer, youTubeService, fileService)
app := h.Serve()
logrus.Fatal(app.Listen(":" + config.Cfg.Port))
}