{"id":13413507,"url":"https://github.com/dimiro1/health","last_synced_at":"2026-01-29T10:30:43.324Z","repository":{"id":45193007,"uuid":"53451609","full_name":"dimiro1/health","owner":"dimiro1","description":"An easy to use, extensible health check library for Go applications.","archived":false,"fork":false,"pushed_at":"2023-11-18T16:04:44.000Z","size":103,"stargazers_count":452,"open_issues_count":3,"forks_count":40,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-07-31T20:52:31.020Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dimiro1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-03-08T23:04:43.000Z","updated_at":"2024-07-27T14:13:44.000Z","dependencies_parsed_at":"2024-01-08T15:34:45.232Z","dependency_job_id":null,"html_url":"https://github.com/dimiro1/health","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dimiro1%2Fhealth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dimiro1%2Fhealth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dimiro1%2Fhealth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dimiro1%2Fhealth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dimiro1","download_url":"https://codeload.github.com/dimiro1/health/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221498763,"owners_count":16833057,"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":"2024-07-30T20:01:41.941Z","updated_at":"2026-01-29T10:30:42.850Z","avatar_url":"https://github.com/dimiro1.png","language":"Go","funding_links":[],"categories":["Miscellaneous","Uncategorized","\u003cspan id=\"其他-miscellaneous\"\u003e其他 Miscellaneous\u003c/span\u003e","Microsoft Office","杂项","其他杂项","其他","雜項"],"sub_categories":["Uncategorized","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","Strings","Advanced Console UIs","未分类的","暂未分类","交流","高级控制台界面","暂未分类这些库被放在这里是因为其他类别似乎都不适合。","高級控制台界面"],"readme":"[![Build Status](https://travis-ci.org/dimiro1/health.svg?branch=master)](https://travis-ci.org/dimiro1/health)\n[![Go Report Card](https://goreportcard.com/badge/github.com/dimiro1/health)](https://goreportcard.com/report/github.com/dimiro1/health)\n[![GoDoc](https://godoc.org/github.com/dimiro1/health?status.svg)](https://godoc.org/github.com/dimiro1/health)\n\nTry browsing [the code on Sourcegraph](https://sourcegraph.com/github.com/dimiro1/health)!\n\n# Go Health Check\n\nAn easy to use, extensible health check library for Go applications.\n\n# New package\n\nUse `https://github.com/dimiro1/healthz` for a basic health check implementation.\n\n**Table of Contents**\n\n- [Example](#example)\n- [Motivation](#motivation)\n- [Inspiration](#inspiration)\n- [Installation](#Installation)\n- [API](#api)\n- [Testing](#testing)\n- [Implementing custom checkers](#implementing-custom-checkers)\n- [Implemented health check indicators](#implemented-health-check-indicators)\n- [LICENSE](#license)\n\n# Example\n\n```go\npackage main\n\nimport (\n    \"net/http\"\n    \"database/sql\"\n    \"time\"\n\n    \"github.com/dimiro1/health\"\n    \"github.com/dimiro1/health/url\"\n    \"github.com/dimiro1/health/db\"\n    \"github.com/dimiro1/health/redis\"\n    _ \"github.com/go-sql-driver/mysql\"\n)\n\nfunc main() {\n    database, _ := sql.Open(\"mysql\", \"/\")\n\tmysql := db.NewMySQLChecker(database)\n    timeout := 5 * time.Second\n    \n    companies := health.NewCompositeChecker()\n    companies.AddChecker(\"Microsoft\", url.NewChecker(\"https://www.microsoft.com/\"))\n    companies.AddChecker(\"Oracle\", url.NewChecker(\"https://www.oracle.com/\"))\n    companies.AddChecker(\"Google\", url.NewChecker(\"https://www.google.com/\"))\n\n    handler := health.NewHandler()\n    handler.AddChecker(\"Go\", url.NewCheckerWithTimeout(\"https://golang.org/\", timeout))\n    handler.AddChecker(\"Big Companies\", companies)\n    handler.AddChecker(\"MySQL\", mysql)\n    handler.AddChecker(\"Redis\", redis.NewChecker(\"tcp\", \":6379\"))\n\n    http.Handle(\"/health/\", handler)\n    http.ListenAndServe(\":8080\", nil)\n}\n```\n\n```sh\n$ curl localhost:8080/health/\n```\n\nIf everything is ok the server must respond with HTTP Status 200 OK and have following json in the body.\n\n```json\n{\n    \"Big Companies\": {\n        \"Google\": {\n            \"code\": 200,\n            \"status\": \"UP\"\n        },\n        \"Microsoft\": {\n            \"code\": 200,\n            \"status\": \"UP\"\n        },\n        \"Oracle\": {\n            \"code\": 200,\n            \"status\": \"UP\"\n        },\n        \"status\": \"UP\"\n    },\n    \"Go\": {\n        \"code\": 200,\n        \"status\": \"UP\"\n    },\n    \"MySQL\": {\n        \"status\": \"UP\",\n        \"version\": \"10.1.9-MariaDB\"\n    },\n    \"Redis\": {\n        \"status\": \"UP\",\n        \"version\": \"3.0.5\"\n    },\n    \"status\": \"UP\"\n}\n```\n\nThe server responds with HTTP Status 503 Service Unavailable if the ckeck is Down and the json response could be something like this.\n\n```json\n{\n    \"Big Companies\": {\n        \"Google\": {\n            \"code\": 200,\n            \"status\": \"UP\"\n        },\n        \"Microsoft\": {\n            \"code\": 200,\n            \"status\": \"UP\"\n        },\n        \"Oracle\": {\n            \"code\": 200,\n            \"status\": \"UP\"\n        },\n        \"status\": \"UP\"\n    },\n    \"Go\": {\n        \"code\": 200,\n        \"status\": \"UP\"\n    },\n    \"MySQL\": {\n        \"status\": \"DOWN\",\n        \"error\": \"Error 1044: Access denied for user ''@'localhost' to database 'invalid-database'\",\n    },\n    \"Redis\": {\n        \"status\": \"UP\",\n        \"version\": \"3.0.5\"\n    },\n    \"status\": \"DOWN\"\n}\n```\n\n# Motivation\n\nIt is very important to verify the status of your system, not only the system itself, but all its dependencies, \nIf your system is not Up you can easily know what is the cause of the problem only looking the health check.\n\nAlso it serves as a kind of basic integration test between the systems.\n\n# Inspiration\n\nI took a lot of ideas from the [spring framework](http://spring.io/).\n\n# Installation\n\nThis package is a go getable package.\n\n```sh\n$ go get github.com/dimiro1/health\n```\n\n# API\n\nThe API is stable and I do not have any plans to break compatibility, but I recommend you to vendor this dependency in your project, as it is a good practice.\n\n# Testing\n\nYou have to install the test dependencies.\n\n```sh\n$ go get gopkg.in/DATA-DOG/go-sqlmock.v1\n$ go get github.com/rafaeljusto/redigomock\n```\n\nor you can go get this package with the -t flag\n\n```sh\ngo get -t github.com/dimiro1/health\n```\n\n# Implementing custom checkers\n\nThe key interface is `health.Checker`, you only have to implement a type that satisfies that interface.\n\n```go\ntype Checker interface {\n\tCheck() Health\n}\n```\n\nHere is an example of Disk Space usage (unix only).\n\n```go\npackage main\n\nimport (\n    \"syscall\"\n    \"os\"\n)\n\ntype DiskSpaceChecker struct {\n\tDir       string\n\tThreshold uint64\n}\n\nfunc NewDiskSpaceChecker(dir string, threshold uint64) DiskSpaceChecker {\n\treturn DiskSpaceChecker{Dir: dir, Threshold: threshold}\n}\n\nfunc (d DiskSpaceChecker) Check() health.Health {\n\thealth := health.NewHealth()\n\n\tvar stat syscall.Statfs_t\n\n\twd, err := os.Getwd()\n\n\tif err != nil {\n        health.Down().AddInfo(\"error\", err.Error()) // Why the check is Down\n        return health\n\t}\n\n\tsyscall.Statfs(wd, \u0026stat)\n\n\tdiskFreeInBytes := stat.Bavail * uint64(stat.Bsize)\n\n\tif diskFreeInBytes \u003c d.Threshold {\n\t\thealth.Down()\n\t} else {\n        health.Up()\n    }\n\n    health.\n        AddInfo(\"free\", diskFreeInBytes).\n        AddInfo(\"threshold\", d.Threshold)\n\n\treturn health\n}\n```\n\n## Important\n\nThe **status** key in the json has priority over a **status** key added by a Checker, so if some checker adds a **status** key to the json, it will not be rendered  \n\n# Implemented health check indicators\n\n| Health         | Description                            | Package                                              |\n|----------------|----------------------------------------|------------------------------------------------------|\n| url.Checker    | Check the connection with some URL     | https://github.com/dimiro1/health/tree/master/url    |\n| db.Checker     | Check the connection with the database | https://github.com/dimiro1/health/tree/master/db     |\n| redis.Checker  | Check the connection with the redis    | https://github.com/dimiro1/health/tree/master/redis  |\n\n# LICENSE\n\nThe MIT License (MIT)\n\nCopyright (c) 2016 Claudemiro\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdimiro1%2Fhealth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdimiro1%2Fhealth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdimiro1%2Fhealth/lists"}