-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
65 lines (51 loc) · 1.03 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
package app
import (
"github.com/sirupsen/logrus"
"playhead/model"
"playhead/db"
)
type App struct {
Config *Config
Database *db.Database
}
func (a *App) NewContext() *Context {
return &Context{
Logger: logrus.StandardLogger(),
Database: a.Database,
}
}
func New() (app *App, err error) {
app = &App{}
app.Config, err = InitConfig()
if err != nil {
return nil, err
}
dbConfig, err := db.InitConfig()
if err != nil {
return nil, err
}
app.Database, err = db.New(dbConfig)
if err != nil {
return nil, err
}
return app, err
}
func (a *App) Close() error {
return a.Database.Close()
}
type ValidationError struct {
Message string `json:"message"`
}
func (e *ValidationError) Error() string {
return e.Message
}
type UserPlayheadError struct {
Message string `json:"message"`
StatusCode int `json:"-"`
}
func (e *UserPlayheadError) Error() string {
return e.Message
}
func (a *App) ValidateBearerToken(token string) (user *model.User, failureReason string, err error) {
return user, failureReason, err
}