{"id":17436025,"url":"https://github.com/cploutarchou/gomultisocket","last_synced_at":"2025-03-28T01:21:40.031Z","repository":{"id":257807750,"uuid":"866483527","full_name":"cploutarchou/GoMultiSocket","owner":"cploutarchou","description":"A SOLID Go WebSocket implementation supporting multiple topics for real-time communication.","archived":false,"fork":false,"pushed_at":"2024-10-02T18:16:15.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-02T03:17:46.851Z","etag":null,"topics":["go","golang","multible-topics","real-time","socket","sockets","solid","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/cploutarchou.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-10-02T10:49:08.000Z","updated_at":"2024-10-02T18:10:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"b874b24c-1ce6-48b5-aa2e-84bab3441267","html_url":"https://github.com/cploutarchou/GoMultiSocket","commit_stats":null,"previous_names":["cploutarchou/gomultisocket"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cploutarchou%2FGoMultiSocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cploutarchou%2FGoMultiSocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cploutarchou%2FGoMultiSocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cploutarchou%2FGoMultiSocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cploutarchou","download_url":"https://codeload.github.com/cploutarchou/GoMultiSocket/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245950516,"owners_count":20699085,"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","multible-topics","real-time","socket","sockets","solid","websocket","ws"],"created_at":"2024-10-17T10:01:34.694Z","updated_at":"2025-03-28T01:21:40.002Z","avatar_url":"https://github.com/cploutarchou.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GoMultiSocket\n![Go Report Card](https://goreportcard.com/badge/github.com/cploutarchou/GoMultiSocket)\n\nA SOLID Go WebSocket implementation with support for multiple topics.\n\n## Features\n\n- WebSocket connection management\n- Support for multiple topics (channels)\n- Broadcast messages to specific topics\n- Lightweight and scalable\n- Easy to extend\n\n## Installation\n\nTo install the GoMultiSocket package, run the following command:\n\n```bash\ngo get github.com/cploutarchou/GoMultiSocket/hub\n```\n\nThen, import the package into your project:\n\n```go\nimport \"github.com/cploutarchou/GoMultiSocket/hub\"\n```\n## Usage\nHere is a simple example of how to use GoMultiSocket to create a WebSocket server that supports multiple topics:\n\n### Example:\n```go\n\npackage main\n\nimport (\n\t\"github.com/cploutarchou/GoMultiSocket/hub\"\n\t\"github.com/gorilla/websocket\"\n\t\"log\"\n\t\"net/http\"\n)\n\n// Upgrader to convert HTTP connections to WebSocket\nvar upgrader = websocket.Upgrader{\n\tCheckOrigin: func(r *http.Request) bool { return true },\n}\n\n// Serve WebSocket connections and register them to the hub\nfunc serveWs(hub *hub.Hub, w http.ResponseWriter, r *http.Request) {\n\tconn, err := upgrader.Upgrade(w, r, nil)\n\tif err != nil {\n\t\tlog.Println(\"Error upgrading to WebSocket:\", err)\n\t\treturn\n\t}\n\thub.HandleClientConnection(conn)\n}\n\nfunc main() {\n\t// Create a new hub instance and start its event loop\n\thub := hub.NewHub()\n\tgo hub.Run()\n\n\t// HTTP handler to handle WebSocket requests\n\thttp.HandleFunc(\"/ws\", func(w http.ResponseWriter, r *http.Request) {\n\t\tserveWs(hub, w, r)\n\t})\n\n\t// Start the WebSocket server\n\tlog.Println(\"WebSocket server started on :8081\")\n\tlog.Fatal(http.ListenAndServe(\":8081\", nil))\n}\n\n```\n\n## Sending and Receiving Messages\nWhen a client connects to the WebSocket, they can send and receive JSON-encoded messages with the following structure:\n\n### Message Format:\n\n```json\n{\n\t\"topic\": \"example-topic\",\n\t\"data\": {\n\t\t\"user\": \"Alice\",\n\t\t\"message\": \"Hello, World!\"\n\t}\n}\n\n```\n\n1. Subscribe to a topic: Once a client sends a message with a specific topic (e.g., \"example-topic\"), it subscribes to that topic.\n2. Broadcasting messages: The server will broadcast messages to all clients subscribed to the same topic.\n\n### Example Client (JavaScript):\n```js\n\nconst socket = new WebSocket(\"ws://localhost:8081/ws\");\n\nsocket.onopen = function() {\n    console.log(\"Connected to WebSocket\");\n\n    // Send a message to the server\n    socket.send(JSON.stringify({\n        topic: \"chat\",\n        data: { user: \"Alice\", message: \"Hello, everyone!\" }\n    }));\n};\n\nsocket.onmessage = function(event) {\n    const message = JSON.parse(event.data);\n    console.log(\"Received message:\", message);\n};\n\nsocket.onclose = function() {\n    console.log(\"Disconnected from WebSocket\");\n};\n\n```\n\n## License\nThis project is licensed under the MIT License - see the [LICENSE](LICENCE) file for details.\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcploutarchou%2Fgomultisocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcploutarchou%2Fgomultisocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcploutarchou%2Fgomultisocket/lists"}