1
0
mirror of https://github.com/alice-lg/alice-lg.git synced 2024-05-11 05:55:03 +00:00

added basic server status endpoint

This commit is contained in:
Matthias Hannig
2017-05-19 11:32:22 +02:00
parent 76b7f4a9e4
commit c7b8f5f573
2 changed files with 43 additions and 1 deletions

View File

@@ -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{

34
backend/status.go Normal file
View File

@@ -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")
}