-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
70 lines (56 loc) · 1.7 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
65
66
67
68
69
70
package main
import (
"catmcgee/config"
"catmcgee/controller"
"catmcgee/repository"
"catmcgee/service"
"database/sql"
"fmt"
"github.com/gin-gonic/gin"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database/postgres"
_ "github.com/golang-migrate/migrate/v4/source/file"
_ "github.com/lib/pq"
"github.com/sirupsen/logrus"
)
func init() {
logrus.SetFormatter(&logrus.JSONFormatter{})
}
func main() {
if err := config.Load(); err != nil {
logrus.Fatal(err)
}
host := config.Configuration.Db.Host
port := config.Configuration.Db.Port
user := config.Configuration.Db.User
password := config.Configuration.Db.Password
dbname := config.Configuration.Db.DatabaseName
connectionString := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", host, port, user, password, dbname)
db, err := sql.Open("postgres", connectionString)
if err != nil {
logrus.Fatal(err)
}
if err := db.Ping(); err != nil {
logrus.Fatal(err)
}
repository.SetDatabase(db)
driver, err := postgres.WithInstance(db, &postgres.Config{})
if err != nil {
logrus.Fatal(err)
}
migrations, err := migrate.NewWithDatabaseInstance("file://migrations", "posgtres", driver)
if err != nil {
logrus.Fatal(err)
}
logrus.Println(migrations.Up())
go func() {
service.GetYouTubeVideos(config.Configuration.YouTube.Region, config.Configuration.YouTube.TotalNumbersOfVideosToDownload)
}()
go func() {
service.StartProcessingVideos(config.Configuration.Processing.NumberOfWorkers)
}()
router := gin.Default()
router.GET("/search", controller.Search)
router.GET("/images/:id", controller.GetImage)
logrus.Fatal(router.Run(fmt.Sprintf(":%d", config.Configuration.Server.Port)))
}