forked from fabric8-services/fabric8-wit
/
status.go
49 lines (42 loc) · 1.18 KB
/
status.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
package controller
import (
"time"
"github.com/fabric8-services/fabric8-wit/app"
"github.com/goadesign/goa"
"github.com/jinzhu/gorm"
)
var (
// Commit current build commit set by build script
Commit = "0"
// BuildTime set by build script in ISO 8601 (UTC) format: YYYY-MM-DDThh:mm:ssTZD (see https://www.w3.org/TR/NOTE-datetime for details)
BuildTime = "0"
// StartTime in ISO 8601 (UTC) format
StartTime = time.Now().UTC().Format("2006-01-02T15:04:05Z")
)
// StatusController implements the status resource.
type StatusController struct {
*goa.Controller
db *gorm.DB
}
// NewStatusController creates a status controller.
func NewStatusController(service *goa.Service, db *gorm.DB) *StatusController {
return &StatusController{
Controller: service.NewController("StatusController"),
db: db,
}
}
// Show runs the show action.
func (c *StatusController) Show(ctx *app.ShowStatusContext) error {
res := &app.Status{}
res.Commit = Commit
res.BuildTime = BuildTime
res.StartTime = StartTime
_, err := c.db.DB().Exec("select 1")
if err != nil {
var message string
message = err.Error()
res.Error = &message
return ctx.ServiceUnavailable(res)
}
return ctx.OK(res)
}