{"id":20690908,"url":"https://github.com/ndthuan/websocketserver","last_synced_at":"2026-05-30T22:32:00.289Z","repository":{"id":144237268,"uuid":"341092509","full_name":"ndthuan/websocketserver","owner":"ndthuan","description":"Standardized WebSocket messages handling in Go","archived":false,"fork":false,"pushed_at":"2021-02-26T01:35:17.000Z","size":19,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-11T01:27:57.843Z","etag":null,"topics":["golang","websocket","websocket-server"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ndthuan.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":"2021-02-22T05:43:49.000Z","updated_at":"2022-09-21T11:17:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"bd79d8b3-cad1-46dd-9dc0-4d43fe3c24f6","html_url":"https://github.com/ndthuan/websocketserver","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ndthuan/websocketserver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndthuan%2Fwebsocketserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndthuan%2Fwebsocketserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndthuan%2Fwebsocketserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndthuan%2Fwebsocketserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ndthuan","download_url":"https://codeload.github.com/ndthuan/websocketserver/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndthuan%2Fwebsocketserver/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33712579,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-30T02:00:06.278Z","response_time":92,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["golang","websocket","websocket-server"],"created_at":"2024-11-16T23:14:45.331Z","updated_at":"2026-05-30T22:32:00.267Z","avatar_url":"https://github.com/ndthuan.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WebSocketServer\nWebSocketServer helps you to organize code by introducing a consistent message format. Messages are routed to handlers based on their types.\n\nThis is a wrapper of the lower level library `gorilla/websocket`.\n\n# Installation\n```shell\ngo get github.com/ndthuan/websocketserver\n```\nImport:\n```go\npackage main\n\nimport \"github.com/ndthuan/websocketserver\"\n```\n\n# Features\n* Works with JSON standardized messages\n```json\n{\n  \"type\": \"message-type\",\n  \"payload\": \"any kind of string, usually json-encoded\"\n}\n```\n* Super easy to use: messages are routed to registered handlers based on message type (think router)\n```go\nwsServer.On(\"login\", loginHandler())\nwsServer.On(\"logout\", logoutHandler())\nwsServer.On(\"human-message\", humanMessageHandler())\n```\n* Ability to broadcast customized messages to all connected clients (see below)\n* A standalone runner can be started in a separate goroutine to proactively broadcast messages to all clients without receiving a message\n```go\npackage main\n\nimport (\n\t\"github.com/gorilla/websocket\"\n\t\"github.com/ndthuan/websocketserver\"\n\t\"time\"\n)\n\nfunc broadcastMessageBuilder(conn *websocket.Conn) (*websocketserver.Message, bool) {\n\tmsg := \u0026websocketserver.Message{\n\t\tType:    \"system-broadcast\",\n\t\tPayload: \"Hi, how are you?\",\n\t}\n\t\n\treturn msg, true\n}\n\nfunc standaloneRunner() websocketserver.StandaloneRunner {\n\treturn func(server *websocketserver.Server) {\n\t\tfor {\n\t\t\ttime.Sleep(time.Second)\n\n\t\t\tserver.Broadcast(broadcastMessageBuilder)\n\t\t}\n\t}\n}\n\nwsServer.SetStandaloneRunner(standaloneRunner())\n```\n* Can be integrated with any framework because the underlying library `gorilla/websocket` works with the standard Go HTTP server\n* Hooks for connection events\n```go\nwsServer.OnConnected(connectedCallback())\nwsServer.OnDisconnected(disconnectedCallback())\n```\n\n# Examples\nSee [a simple chat server](./examples/chat-server/) for an example of how it is used.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndthuan%2Fwebsocketserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fndthuan%2Fwebsocketserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndthuan%2Fwebsocketserver/lists"}