mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 17:24:26 +08:00
add health check api
This commit is contained in:
@@ -131,6 +131,8 @@ func startWebServer(c *cli.Context) error {
|
|||||||
router.StaticFile("/desktop/touchicon.png", filepath.Join(config.StaticRootPath, "touchicon.png"))
|
router.StaticFile("/desktop/touchicon.png", filepath.Join(config.StaticRootPath, "touchicon.png"))
|
||||||
router.StaticFile("/desktop/manifest.json", filepath.Join(config.StaticRootPath, "manifest.json"))
|
router.StaticFile("/desktop/manifest.json", filepath.Join(config.StaticRootPath, "manifest.json"))
|
||||||
|
|
||||||
|
router.GET("/healthz.json", bindApi(api.Healths.HealthStatusHandler))
|
||||||
|
|
||||||
apiRoute := router.Group("/api")
|
apiRoute := router.Group("/api")
|
||||||
|
|
||||||
apiRoute.Use(bindMiddleware(middlewares.RequestId(config)))
|
apiRoute.Use(bindMiddleware(middlewares.RequestId(config)))
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
|
||||||
"github.com/mayswind/ezbookkeeping/cmd"
|
"github.com/mayswind/ezbookkeeping/cmd"
|
||||||
|
"github.com/mayswind/ezbookkeeping/pkg/settings"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/utils"
|
"github.com/mayswind/ezbookkeeping/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -24,6 +25,9 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
settings.Version = Version
|
||||||
|
settings.CommitHash = CommitHash
|
||||||
|
|
||||||
app := &cli.App{
|
app := &cli.App{
|
||||||
Name: "ezBookkeeping",
|
Name: "ezBookkeeping",
|
||||||
Usage: "A lightweight personal bookkeeping app hosted by yourself.",
|
Usage: "A lightweight personal bookkeeping app hosted by yourself.",
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/mayswind/ezbookkeeping/pkg/core"
|
||||||
|
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
||||||
|
"github.com/mayswind/ezbookkeeping/pkg/settings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// HealthsApi represents health api
|
||||||
|
type HealthsApi struct{}
|
||||||
|
|
||||||
|
// Initialize a healths api singleton instance
|
||||||
|
var (
|
||||||
|
Healths = &HealthsApi{}
|
||||||
|
)
|
||||||
|
|
||||||
|
// HealthStatusHandler returns the health status of current service
|
||||||
|
func (a *HealthsApi) HealthStatusHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||||
|
result := make(map[string]string)
|
||||||
|
|
||||||
|
result["version"] = settings.Version
|
||||||
|
result["commit"] = settings.CommitHash
|
||||||
|
result["status"] = "ok"
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@@ -7,7 +7,9 @@ type ConfigContainer struct {
|
|||||||
|
|
||||||
// Initialize a config container singleton instance
|
// Initialize a config container singleton instance
|
||||||
var (
|
var (
|
||||||
Container = &ConfigContainer{}
|
Version string
|
||||||
|
CommitHash string
|
||||||
|
Container = &ConfigContainer{}
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetCurrentConfig sets the current config by a given config
|
// SetCurrentConfig sets the current config by a given config
|
||||||
|
|||||||
Reference in New Issue
Block a user