-
Notifications
You must be signed in to change notification settings - Fork 29
/
mainvm.go
51 lines (40 loc) · 1.21 KB
/
mainvm.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
// +build appenginevm
package main
import (
"os"
"github.com/go-kit/kit/log"
"github.com/goadesign/goa"
"github.com/goadesign/goa-cellar/app"
"github.com/goadesign/goa-cellar/controllers"
"github.com/goadesign/goa-cellar/store"
"github.com/goadesign/goa/logging/kit"
"github.com/goadesign/goa/middleware"
)
func main() {
// Create goa service
service := goa.New("cellar")
// Setup logger
w := log.NewSyncWriter(os.Stderr)
logger := log.NewLogfmtLogger(w)
service.WithLogger(goakit.New(logger))
// Setup basic middleware
service.Use(middleware.RequestID())
service.Use(middleware.LogRequest(true))
service.Use(middleware.ErrorHandler(service, true))
service.Use(middleware.Recover())
// Instantiate DB
db := store.NewDB()
// Mount account controller onto service
ac := controllers.NewAccount(service, db)
app.MountAccountController(service, ac)
// Mount bottle controller onto service
bc := controllers.NewBottle(service, db)
app.MountBottleController(service, bc)
// Mount health-check controller onto service
hc := controllers.NewHealth(service, db)
app.MountHealthController(service, hc)
// Run service
if err := service.ListenAndServe(":8080"); err != nil {
service.LogError(err.Error())
}
}