{"id":20655696,"url":"https://github.com/remast/go_websocket_turbo","last_synced_at":"2025-04-19T12:13:47.709Z","repository":{"id":145093741,"uuid":"325641462","full_name":"remast/go_websocket_turbo","owner":"remast","description":"Simple example for using Turbos Streams in Go with the Gorilla WebSocket toolkit.","archived":false,"fork":false,"pushed_at":"2024-06-14T07:43:58.000Z","size":18,"stargazers_count":31,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T07:41:45.627Z","etag":null,"topics":[],"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/remast.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":"2020-12-30T20:25:16.000Z","updated_at":"2024-10-31T00:51:21.000Z","dependencies_parsed_at":"2024-05-16T07:28:17.748Z","dependency_job_id":null,"html_url":"https://github.com/remast/go_websocket_turbo","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/remast%2Fgo_websocket_turbo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remast%2Fgo_websocket_turbo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remast%2Fgo_websocket_turbo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remast%2Fgo_websocket_turbo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/remast","download_url":"https://codeload.github.com/remast/go_websocket_turbo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249691632,"owners_count":21311375,"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-16T18:12:20.584Z","updated_at":"2025-04-19T12:13:47.682Z","avatar_url":"https://github.com/remast.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go Example for TurboStreams over WebSockets\n\nSimple example for using [Turbo](https://turbo.hotwire.dev/)s [Stream](https://turbo.hotwire.dev/reference/streams)s in Go with the [Gorilla WebSocket](https://github.com/gorilla/websocket) toolkit.\n\nRun the sample using the following command:\n\n    $ go run *.go\n\nTo use the chat example, open http://localhost:8080/ in your browser.\n\n## Frontend\nThe frontend connects to the Turbo Stream using plain JavaScript like:\n\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/@hotwired/turbo@8.0.4/dist/turbo.es2017-umd.min.js\" \u003e\u003c/script\u003e\n\u003cscript\u003e\nTurbo.connectStreamSource(new WebSocket(\"ws://\" + document.location.host + \"/ws\"));\n\u003c/script\u003e\n```\n\nAfter that the frontend is connected to the Turbo Stream and get's all messages. Every chat message is appended to the dom element with id `board`.\n\nThis _should_ work with html markup too but I have not gotten it working yet.\n\n## Server\n\nThe server receives the new chat message via web socket. Then it wraps the message as Turbo Stream action with action `append` and broadcasts it to all subscribers. That way all subscribed users see the new message on the board.\n\nThe raw text message sent over the web socket is:\n```json\n{ \n  \"identifier\": \n     \"{\\\"channel\\\":\\\"Turbo::StreamsChannel\\\",  \\\"signed_stream_name\\\":\\\"**mysignature**\\\"}\",\n  \"message\":\n    \"\u003cturbo-stream action='append' target='board'\u003e\n  \t\u003ctemplate\u003e\n  \t\t\u003cp\u003eMy new Message\u003c/p\u003e\n  \t\u003c/template\u003e\n     \u003c/turbo-stream\u003e\"\n}\n```\n\n## Credits\n\nBased on [Gorilla WebSocket Chat Example](https://github.com/gorilla/websocket/tree/master/examples/chat)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremast%2Fgo_websocket_turbo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fremast%2Fgo_websocket_turbo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremast%2Fgo_websocket_turbo/lists"}