-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
56 lines (46 loc) · 1.24 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
//go:generate goagen bootstrap -d goaAPIKeyUserAuth/design
package main
import (
"goaAPIKeyUserAuth/app"
"github.com/goadesign/goa"
"github.com/goadesign/goa/middleware"
"github.com/jinzhu/gorm"
)
var (
// ErrUnauthorized is the error returned for unauthorized requests.
ErrUnauthorized = goa.NewErrorClass("unauthorized", 401)
)
var db *gorm.DB
func main() {
// Create service
service := goa.New("")
// Mount middleware
service.Use(middleware.RequestID())
service.Use(middleware.LogRequest(true))
service.Use(middleware.ErrorHandler(service, true))
service.Use(middleware.Recover())
// middleware
app.UseAPIKeyMiddleware(service, NewAPIKeyMiddleware())
// Mount "user" controller
c := NewUserController(service)
app.MountUserController(service, c)
db, _ = gorm.Open("mysql", "root:password@/database")
LoadSession()
// Start service
if err := service.ListenAndServe(":9001"); err != nil {
service.LogError("startup", "err", err)
}
}
func LoadSession() {
session := []Session{}
if db.Find(&session).RecordNotFound() != true {
for _, row := range session {
sessStore[row.Key] = Session{
Key: row.Key,
UserID: row.UserID,
UserName: row.UserName,
LastAccessed: row.LastAccessed,
}
}
}
}