-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
74 lines (64 loc) · 1.55 KB
/
app.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
71
72
73
74
package movielite
import (
"fmt"
"net/http"
"github.com/gammazero/workerpool"
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm"
"github.com/ms900ft/movielite/models"
"github.com/ryanbradynd05/go-tmdb"
log "github.com/sirupsen/logrus"
)
const (
DEFLANG = "de-DE"
WATCHLIST = "watchlist"
)
//Service mal sehen
type Service struct {
Router *gin.Engine
DB *gorm.DB
Token *models.Token
Config *Config
WorkerPool *workerpool.WorkerPool
TMDBClient models.TMDBClients
//Config Config
}
type meta struct {
Total int64 `json:"total"`
}
//Initialize mal sehen
func (a *Service) Initialize() {
var err error
dbc := models.DBConfig{DBName: a.Config.DataBase, InitialAdminPassword: a.Config.InitialAdminPassword}
a.DB = models.ConnectDataBase(dbc) // new
if a.Config.SQLDebug {
a.DB.LogMode(true)
}
if err != nil {
log.Fatal(err)
}
tmdbClient := tmdb.Init(tmdb.Config{APIKey: a.Config.TMDBApiKey})
// pool to slow down tmpdb image requests
a.WorkerPool = workerpool.New(1)
models.HttpClient = &http.Client{}
//sa.TMDBClient = new(models.TMDBClient)
a.TMDBClient = tmdbClient
if a.Config.Mode == "prod" {
gin.SetMode(gin.ReleaseMode)
log.SetLevel(log.InfoLevel)
} else {
gin.SetMode(gin.DebugMode)
log.SetLevel(log.DebugLevel)
}
a.Router = gin.Default()
//a.Router.Use(CORSMiddleware())
a.Router.Use(gin.Recovery())
a.initializeRoutes()
}
//Run mal sehen
func (a *Service) Run() error {
p := fmt.Sprintf(":%d", a.Config.Port)
log.Debug("running on port: " + p)
err := http.ListenAndServe(p, a.Router)
return err
}