{"id":16934385,"url":"https://github.com/codeskyblue/heartbeat","last_synced_at":"2025-07-19T15:04:34.558Z","repository":{"id":9536461,"uuid":"11439510","full_name":"codeskyblue/heartbeat","owner":"codeskyblue","description":"heart beat for process status check. (心跳检测，UDP协议)","archived":false,"fork":false,"pushed_at":"2018-12-17T03:27:06.000Z","size":26,"stargazers_count":23,"open_issues_count":1,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-11T18:56:59.721Z","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":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codeskyblue.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}},"created_at":"2013-07-16T03:10:12.000Z","updated_at":"2024-07-09T09:48:24.000Z","dependencies_parsed_at":"2022-09-26T20:31:23.952Z","dependency_job_id":null,"html_url":"https://github.com/codeskyblue/heartbeat","commit_stats":null,"previous_names":["shxsun/heartbeat"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/codeskyblue/heartbeat","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeskyblue%2Fheartbeat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeskyblue%2Fheartbeat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeskyblue%2Fheartbeat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeskyblue%2Fheartbeat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codeskyblue","download_url":"https://codeload.github.com/codeskyblue/heartbeat/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeskyblue%2Fheartbeat/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265950467,"owners_count":23853757,"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-10-13T20:51:58.610Z","updated_at":"2025-07-19T15:04:34.536Z","avatar_url":"https://github.com/codeskyblue.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# heartbeat\r\nImplement a simple hearbeat detect with HTTP protocol with secret.\r\n\r\nFor old version which use UDP protocol. see [tag 1.0](#TODO)\r\n\r\n## Install\r\n```bash\r\ngo get -v github.com/codeskyblue/heartbeat\r\n```\r\n\r\n## Usage\r\nServer and Client should have the same secret.\r\n\r\nServer Example:\r\n\r\n```go\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"net/http\"\r\n\t\"time\"\r\n\r\n\t\"github.com/codeskyblue/heartbeat\"\r\n)\r\n\r\nfunc main() {\r\n\thbs := heartbeat.NewServer(\"my-secret\", 15*time.Second) // secret: my-secret, timeout: 15s\r\n\thbs.OnConnect = func(identifier string, r *http.Request) {\r\n\t\tfmt.Println(identifier, \"is online\")\r\n\t}\r\n\thbs.OnDisconnect = func(identifier string) {\r\n\t\tfmt.Println(identifier, \"is offline\")\r\n\t}\r\n\thttp.Handle(\"/heartbeat\", hbs)\r\n\thttp.ListenAndServe(\":7000\", nil)\r\n}\r\n```\r\n\r\nClient Example:\r\n\r\n```go\r\npackage main\r\n\r\nimport (\r\n\t\"time\"\r\n\r\n\t\"github.com/codeskyblue/heartbeat\"\r\n)\r\n\r\nfunc main() {\r\n\tclient := \u0026heartbeat.Client{\r\n\t\tServerAddr: \"http://localhost:7000/heartbeat\", // replace to your server addr\r\n\t\tSecret:     \"my-secret\",                       // must be save with server secret\r\n\t\tIdentifier: \"client-unique-name\",\r\n\t}\r\n\tcancel := client.Beat(5 * time.Second)\r\n\tdefer cancel() // cancel heartbeat\r\n\t// Do something else\r\n\ttime.Sleep(10 * time.Second)\r\n}\r\n```\r\n\r\n## Protocol\r\n1. client get timestamp from server\r\n2. client send identifier, timestamp and hmac hash to server every interval\r\n3. server send back the new timestamp to client on each request\r\n\r\n# LICENSE\r\n[GNU 2.0](LICENSE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeskyblue%2Fheartbeat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeskyblue%2Fheartbeat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeskyblue%2Fheartbeat/lists"}