{"id":21502391,"url":"https://github.com/night-codes/ws","last_synced_at":"2025-12-15T12:20:43.939Z","repository":{"id":57520038,"uuid":"135903436","full_name":"night-codes/ws","owner":"night-codes","description":"A high performance golang websocket framework","archived":false,"fork":false,"pushed_at":"2023-05-05T02:32:00.000Z","size":49,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-23T23:32:54.598Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/night-codes/ws?tab=doc","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/night-codes.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":"2018-06-03T12:46:24.000Z","updated_at":"2022-08-01T09:05:17.000Z","dependencies_parsed_at":"2024-06-20T17:33:35.885Z","dependency_job_id":"0bdb7067-1057-43d0-8a4d-d79347af3a04","html_url":"https://github.com/night-codes/ws","commit_stats":null,"previous_names":["night-codes/tokay-ws"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/night-codes%2Fws","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/night-codes%2Fws/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/night-codes%2Fws/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/night-codes%2Fws/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/night-codes","download_url":"https://codeload.github.com/night-codes/ws/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244043505,"owners_count":20388593,"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-11-23T18:14:44.482Z","updated_at":"2025-10-26T02:42:27.782Z","avatar_url":"https://github.com/night-codes.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ws\nSimple to use golang websocket client/server library + vanilla js client library.\n\n## Example\n```go\n    package main\n\nimport (\n\t\"log\"\n\t\"net/http\"\n\t\"time\"\n\n\t\"github.com/night-codes/ws\"\n\t// \"github.com/night-codes/ws/fasthttp/connector\"\n\t// \"github.com/night-codes/ws/tokay/connector\"\n\t// \"github.com/night-codes/ws/gin/connector\"\n\t\"github.com/night-codes/ws/http/connector\"\n)\n\nfunc main() {\n\tgo server()\n\ttime.Sleep(time.Second)\n\tgo client()\n\ttime.Sleep(time.Second * 5)\n}\n\n// === SERVER ===\nfunc server() {\n\thandler, mainWS := connector.New()\n\n\t// Listen command from the client and send answer\n\tmainWS.Read(\"test\", func(a *ws.Adapter) {\n\t\tdata := a.Data()\n\t\tlog.Println(\"1)\", string(data))\n\t\ta.Send(\"pong\")\n\t})\n\n\t// Listen command from the client without answer\n\tmainWS.Read(\"command\", func(a *ws.Adapter) {\n\t\tdata := a.Data()\n\t\tlog.Println(\"3)\", string(data))\n\t})\n\n\t// Send command to each client and wait for answer\n\tgo func() {\n\t\ttime.Sleep(time.Second * 2)\n\t\tfor _, conn := range mainWS.GetConnects() {\n\t\t\tif result, err := conn.Request(\"client test\", \"client ping\", time.Second); err == nil {\n\t\t\t\tlog.Println(\"5)\", string(result))\n\t\t\t}\n\t\t}\n\t}()\n\n\t// Listen and serve:\n\n\t// net/http:\n\thttp.Handle(\"/myws\", handler) // [net/http]\n\tlog.Fatal(http.ListenAndServe(\":8080\", nil))\n\n\t// fasthttp:\n\t/* fasthttp.ListenAndServe(\":8080\", func(ctx *fasthttp.RequestCtx) {\n\t\tswitch string(ctx.Path()) {\n\t\tcase \"/myws\":\n\t\t\thandler(ctx)\n\t\tdefault:\n\t\t\tctx.Error(\"Unsupported path\", fasthttp.StatusNotFound)\n\t\t}\n\t}) */\n\n\t// tokay\n\t/* app := tokay.New()\n\tapp.GET(\"/myws\", handler)\n\tpanic(app.Run(\":8080\", \"Application started at %s\")) */\n\n\t// gin\n\t/* app := gin.New()\n\tapp.GET(\"/myws\", handler)\n\tpanic(app.Run(\":8080\")) */\n}\n\n// === CLIENT ===\nfunc client() {\n\tconn := ws.NewClient(\"ws://localhost:8080/myws\")\n\n\t// Send command to the server and wait for answer\n\tif result, err := conn.Request(\"test\", \"ping\", time.Second); err == nil {\n\t\tlog.Println(\"2)\", string(result))\n\t}\n\n\t// Send command to the server without answer waiting\n\tconn.Send(\"command\", \"Server command 1\")\n\tconn.Send(\"command\", \"Server command 2\")\n\tconn.Send(\"command\", \"Server command 3\")\n\n\t// Listen command from the server\n\tconn.Read(\"client test\", func(a *ws.Adapter) {\n\t\tdata := a.Data()\n\t\tlog.Println(\"4)\", string(data))\n\t\ta.Send(\"client pong\")\n\t})\n}\n\n```\n\n## MIT License\n\nCopyright (c) 2018 Oleksiy Chechel\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%2Fnight-codes%2Fws","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnight-codes%2Fws","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnight-codes%2Fws/lists"}