diff --git a/backend/api.go b/backend/api.go index c6b6b15..2e4d834 100644 --- a/backend/api.go +++ b/backend/api.go @@ -71,7 +71,8 @@ func endpoint(wrapped apiEndpoint) httprouter.Handle { // Register api endpoints func apiRegisterEndpoints(router *httprouter.Router) error { - // Config + // Meta + router.GET("/api/status", endpoint(apiStatusShow)) router.GET("/api/config", endpoint(apiConfigShow)) // Routeservers @@ -87,6 +88,13 @@ func apiRegisterEndpoints(router *httprouter.Router) error { return nil } +// Handle Status Endpoint, this is intended for +// monitoring and service health checks +func apiStatusShow(_req *http.Request, _params httprouter.Params) (api.Response, error) { + status, err := NewAppStatus() + return status, err +} + // Handle Config Endpoint func apiConfigShow(_req *http.Request, _params httprouter.Params) (api.Response, error) { result := api.ConfigResponse{ diff --git a/backend/status.go b/backend/status.go new file mode 100644 index 0000000..8f34129 --- /dev/null +++ b/backend/status.go @@ -0,0 +1,34 @@ +package main + +import ( + "strings" + + "github.com/GeertJohan/go.rice" +) + +// Gather application status information +type AppStatus struct { + Version string `json:"version"` +} + +// Get application status, perform health checks +// on backends. +func NewAppStatus() (*AppStatus, error) { + status := &AppStatus{ + Version: statusGetVersion(), + } + return status, nil +} + +// Get application version +func statusGetVersion() string { + meta, err := rice.FindBox("../") + if err != nil { + return "unknown" + } + version, err := meta.String("VERSION") + if err != nil { + return "unknown" + } + return strings.Trim(version, "\n") +}