{"id":29572674,"url":"https://github.com/accelbyte/healthcheck-go-sdk","last_synced_at":"2025-07-19T05:10:51.370Z","repository":{"id":46670573,"uuid":"383308907","full_name":"AccelByte/healthcheck-go-sdk","owner":"AccelByte","description":null,"archived":false,"fork":false,"pushed_at":"2024-05-20T05:37:37.000Z","size":43,"stargazers_count":1,"open_issues_count":0,"forks_count":10,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-06T03:23:54.743Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AccelByte.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.MD","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-06T01:49:00.000Z","updated_at":"2024-05-20T05:28:08.000Z","dependencies_parsed_at":"2023-12-27T11:27:46.341Z","dependency_job_id":"ccc52cce-bbb1-4992-a633-9c7ca68e2050","html_url":"https://github.com/AccelByte/healthcheck-go-sdk","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/AccelByte/healthcheck-go-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AccelByte%2Fhealthcheck-go-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AccelByte%2Fhealthcheck-go-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AccelByte%2Fhealthcheck-go-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AccelByte%2Fhealthcheck-go-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AccelByte","download_url":"https://codeload.github.com/AccelByte/healthcheck-go-sdk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AccelByte%2Fhealthcheck-go-sdk/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265892510,"owners_count":23845032,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-19T05:10:50.671Z","updated_at":"2025-07-19T05:10:51.363Z","avatar_url":"https://github.com/AccelByte.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# healthcheck-go-sdk\n\nThis is library for implementing k8s health check with [go-restful](https://github.com/emicklei/go-restful)\n\nIt provides dependencies health checking which returns dependency info, health status, timestamp and last error information\nof the dependency check result.\n\n\n## What's new in v2\n- Support soft and hard dependency option. `AddHealthCheck` defaults to soft and `AddHardHealthCheck` is available for\n  registering a hard dependency. A soft dependency will not affect the overall healthy status of the service if the dependency is not healthy,\n  meanwhile a hard dependency health will.\n- Support background periodic check instead of immediate check on every `/healthz` request\n- The `/healthz` response now returns last call time, last known good call time, and last error message of the corresponding dependency health check\n- New `UpdateHealth` method to enable the implementer service to update a dependency health\n- CheckFunc templates improvements\n- Add `AlertLevel` to adjust dependency priority when its alerted\n\n## Usage\n#### Installing\n```\ngo get -u github.com/AccelByte/healthcheck-go-sdk/v2\n```\n**NOTE:** since the v2 includes [eventstream-go-sdk v4](https://github.com/AccelByte/eventstream-go-sdk) template check function, you will need to make sure that cgo is enabled (configurable with `CGO_ENABLED=1` environment variable) and parsing `-tags musl` param when building your Go application in Alpine Linux.\n\nReference: https://github.com/AccelByte/eventstream-go-sdk#v4\n\n\n\n#### Initiating\n```go\nh := healthcheck.New(\u0026healthcheck.Config{\n  ServiceName: \"serviceName\",\n  BasePath: \"/servicePath\",\n  BackgroundCheckInterval: 60*time.Second,\n})\n```\n\n#### Registering a dependency health check\n\n```go\nredisClient := new(redis.Client)\ntimeout := 5 * time.Second\nh.AddDependencyHealthCheck(healthcheck.Dependency{\n\t\tName:       \"redis\",\n\t\tURL:        \"redis:6379\",\n\t\tAlertLevel: healthcheck.Important,\n\t\tCheckFunc:  h.RedisHealthCheck(redisClient, timeout),\n})\n```\n\n#### Registering a (soft) dependency (recommended) (DEPRECATED)\n```go\nredisClient := new(redis.Client)\ntimeout := 5 * time.Second\nh.AddHealthCheck(\"redis\", \"redis:6379\", h.RedisHealthCheck(redisClient, timeout))\n```\n\n#### Registering a hard dependency (DEPRECATED)\n```go\nh.AddHardHealthCheck(\"other-dependency\", \"dependency:1234\", func() error {\n// do checking\nreturn nil\n})\n```\n\n#### Use periodic background checking (recommended)\n```go\nh.StartBackgroundCheck(ctx)\n````\n\n#### Registering health check webservice to a go-restful container\n```go\nserviceContainer := restful.NewContainer()\n...\nserviceContainer.Add(h.AddWebservice())\n```\n\n#### Expose dependency health prometheus metrics\n\n```go\nregistry := prometheus.NewRegistry()\nh.AddMetrics(registry)\n\n// or add metrics to default prometheus registry\nh.AddMetrics(prometheus.DefaultRegisterer)\n```\n\n\n### Methods for Updating Health Dependency\n\nThere are two ways for a dependency health to be updated. \n\nThe first one is by attaching a check function when adding a dependency using `AddHealthCheck` or `AddHardHealthCheck` \nas shown in the previous section. It suits well if the dependency already provides a way for doing health check, \nhence the check can be done easily inside the check function.\n\nWhen a dependency does not provide a straight-forward way for health check and there is no easy workaround, we can use \n`UpdateHealth` instead to update the  dependency health. The idea is to update the dependency health status right after \nthe dependency is called.\n\n```go\nh.AddHealthCheck(\"emailProvider\", \"https://email-provider\", nil) // register dependency health check with nil check function\n\n...\n\nerr := emailProvider.Send(from, to, emailBody)\nif err != nil {\n\t_ = h.UpdateHealth(\"emailProvider\", false, \u0026healthcheck.CheckError{Timestamp: time.Now(), Message: err.Error()}) // update health to false with check error included\n\treturn err\n}\n\n_ = h.UpdateHealth(\"emailProvider\", true, nil) // update to healthy if succeed\n```\n\n\n\n### Check Funtion Templates\nHealth check function templates are available at [checks.go](checks.go)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faccelbyte%2Fhealthcheck-go-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faccelbyte%2Fhealthcheck-go-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faccelbyte%2Fhealthcheck-go-sdk/lists"}