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:
@@ -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
34
backend/status.go
Normal 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")
|
||||
}
|
Reference in New Issue
Block a user