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/manifest.json", filepath.Join(config.StaticRootPath, "manifest.json"))
|
||||
|
||||
router.GET("/healthz.json", bindApi(api.Healths.HealthStatusHandler))
|
||||
|
||||
apiRoute := router.Group("/api")
|
||||
|
||||
apiRoute.Use(bindMiddleware(middlewares.RequestId(config)))
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/mayswind/ezbookkeeping/cmd"
|
||||
"github.com/mayswind/ezbookkeeping/pkg/settings"
|
||||
"github.com/mayswind/ezbookkeeping/pkg/utils"
|
||||
)
|
||||
|
||||
@@ -24,6 +25,9 @@ var (
|
||||
)
|
||||
|
||||
func main() {
|
||||
settings.Version = Version
|
||||
settings.CommitHash = CommitHash
|
||||
|
||||
app := &cli.App{
|
||||
Name: "ezBookkeeping",
|
||||
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
|
||||
var (
|
||||
Container = &ConfigContainer{}
|
||||
Version string
|
||||
CommitHash string
|
||||
Container = &ConfigContainer{}
|
||||
)
|
||||
|
||||
// SetCurrentConfig sets the current config by a given config
|
||||
|
||||
Reference in New Issue
Block a user