{"id":18812189,"url":"https://github.com/mqenergy/go-websocket","last_synced_at":"2025-10-23T20:33:13.188Z","repository":{"id":49828691,"uuid":"515486137","full_name":"MQEnergy/go-websocket","owner":"MQEnergy","description":"基于gorilla/websocket封装的websocket库，实现基于系统维度的消息推送，基于群组维度的消息推送，基于单个和多个客户端消息推送。","archived":false,"fork":false,"pushed_at":"2024-10-24T10:04:51.000Z","size":94,"stargazers_count":21,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-13T21:08:26.198Z","etag":null,"topics":["go","golang","gorilla-websocket","push","websocket","ws"],"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/MQEnergy.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-19T07:45:57.000Z","updated_at":"2024-10-24T10:04:54.000Z","dependencies_parsed_at":"2024-11-07T23:31:49.919Z","dependency_job_id":"0b1dd069-2d58-48ae-996d-cd6ae0da6cd3","html_url":"https://github.com/MQEnergy/go-websocket","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/MQEnergy%2Fgo-websocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MQEnergy%2Fgo-websocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MQEnergy%2Fgo-websocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MQEnergy%2Fgo-websocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MQEnergy","download_url":"https://codeload.github.com/MQEnergy/go-websocket/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248782270,"owners_count":21160717,"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":["go","golang","gorilla-websocket","push","websocket","ws"],"created_at":"2024-11-07T23:30:28.215Z","updated_at":"2025-10-23T20:33:08.149Z","avatar_url":"https://github.com/MQEnergy.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-websocket\n基于gorilla/websocket封装的websocket库，实现基于系统维度的消息推送，基于群组维度的消息推送，基于单个和多个客户端消息推送。\n\n[![GoDoc](https://godoc.org/github.com/MQEnergy/go-websocket/?status.svg)](https://pkg.go.dev/github.com/MQEnergy/go-websocket)\n[![Go Report Card](https://goreportcard.com/badge/github.com/MQEnergy/go-websocket)](https://goreportcard.com/report/github.com/MQEnergy/go-websocket)\n[![codebeat badge](https://codebeat.co/badges/063ec0b6-5059-4b1b-92c0-4f750438faa8)](https://codebeat.co/projects/github-com-mqenergy-go-websocket-main)\n[![GitHub license](https://img.shields.io/github/license/MQEnergy/go-websocket)](https://github.com/MQEnergy/go-websocket/blob/main/LICENSE)\n\n## 一、目录结构\n```\n├── LICENSE\n├── README.md\n├── client.go           // 客户端\n├── client_hub.go       // 客户端集线器\n├── code.go             // 状态码\n├── example             // 案例\n│   └── ws.go\n├── go.mod\n├── go.sum\n├── log.go              // 日志\n├── node.go             // 节点（用于在分布式系统生成基于节点的客户端连接ID）\n├── response.go         // 客户端发送消息\n└── server.go           // 服务\n\n```\n## 二、在项目中安装使用\n```go\ngo get -u github.com/MQEnergy/go-websocket\n```\n## 三、运行example\n### 1、开启服务\n```go\ngo run examples/ws.go\n```\n```\n服务器启动成功，端口号 :9991 \n```\n代表启动成功\n\n### 2、案例\n具体查看example目录\n\n#### 1）连接ws并加群组\nsystem_id为系统ID（不必填 不填默认当前节点ip的int值）\ngroup_id为群组ID（不必填 不填连接不加群组 注意：群组id为全局唯一ID 不然可能会出现不同系统的相同群组都推送消息）\n\n请求\n```\nws://127.0.0.1:9991/ws?system_id=123\u0026group_id=test\n```\n可选多种返回方式 如： Text，Json，Binary（二进制方式）\n返回如下json示例：\n```\n{\n    \"code\": 0,\n    \"msg\": \"客户端连接成功\",\n    \"data\": {\n        \"client_id\": \"1589962851152388096\",\n        \"group_id\": \"test\",\n        \"system_id\": \"123\"\n    },\n    \"params\": null\n}\n```\n\n#### 2）全局广播消息群发\n请求\n```\nhttp://127.0.0.1:9991/push_to_system?system_id=123\u0026data={\"hello\":\"world\"}\n```\n返回\n```\n{\n    \"msg\": \"系统消息发送成功\",\n}\n```\n\n#### 3）单个系统消息群发\n请求\n```\nhttp://127.0.0.1:9991/push_to_system?system_id=123\u0026data={\"hello\":\"world\"}\n```\n返回\n```\n{\n    \"msg\": \"系统消息发送成功\",\n}\n```\n\n#### 4）推送消息到群组\n请求\n```\nhttp://127.0.0.1:9991/push_to_group?system_id=123\u0026group_id=test\u0026data={\"hello\":\"world1\"}\n```\n返回\n```\n{\n    \"msg\": \"群组消息发送成功\",\n}\n```\n\n#### 5）单个客户端消息发送\n请求\n```\nhttp://127.0.0.1:9991/push_to_client?client_id=123\u0026data={\"hello\":\"world\"}\n```\n返回\n```\n{\n    \"msg\": \"客户端消息发送成功\",\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmqenergy%2Fgo-websocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmqenergy%2Fgo-websocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmqenergy%2Fgo-websocket/lists"}