{"id":13413413,"url":"https://github.com/olahol/melody","last_synced_at":"2025-04-23T20:45:19.592Z","repository":{"id":32002119,"uuid":"35573029","full_name":"olahol/melody","owner":"olahol","description":":notes: Minimalist websocket framework for Go","archived":false,"fork":false,"pushed_at":"2024-07-25T18:08:25.000Z","size":1011,"stargazers_count":3885,"open_issues_count":13,"forks_count":371,"subscribers_count":64,"default_branch":"master","last_synced_at":"2025-04-08T17:14:06.479Z","etag":null,"topics":["example","framework","go","golang","minimalist","websocket","websocket-framework"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/olahol.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2015-05-13T20:38:32.000Z","updated_at":"2025-04-08T09:43:42.000Z","dependencies_parsed_at":"2023-01-14T20:18:40.451Z","dependency_job_id":"61b47e22-41cb-4fe1-9218-2459d9a5dd66","html_url":"https://github.com/olahol/melody","commit_stats":{"total_commits":119,"total_committers":17,"mean_commits":7.0,"dds":0.5630252100840336,"last_synced_commit":"6bf86153260ddfd8ef1929323e0ee37cc3acd44a"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olahol%2Fmelody","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olahol%2Fmelody/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olahol%2Fmelody/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olahol%2Fmelody/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/olahol","download_url":"https://codeload.github.com/olahol/melody/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250513380,"owners_count":21443200,"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":["example","framework","go","golang","minimalist","websocket","websocket-framework"],"created_at":"2024-07-30T20:01:39.788Z","updated_at":"2025-04-23T20:45:19.567Z","avatar_url":"https://github.com/olahol.png","language":"Go","funding_links":[],"categories":["开源类库","Go","WebSocket","Repositories","Programming","消息","Messaging","Open source library","消息系统","websocket","Relational Databases","机器学习","\u003cspan id=\"消息-messaging\"\u003e消息 Messaging\u003c/span\u003e","消息传递"],"sub_categories":["WebSocket","Golang","检索及分析资料库","Search and Analytic Databases","SQL 查询语句构建库","Advanced Console UIs","高级控制台界面","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","高級控制台界面","交流"],"readme":"# melody\n\n![Build Status](https://github.com/olahol/melody/actions/workflows/test.yml/badge.svg)\n[![Codecov](https://img.shields.io/codecov/c/github/olahol/melody)](https://app.codecov.io/github/olahol/melody)\n[![Go Report Card](https://goreportcard.com/badge/github.com/olahol/melody)](https://goreportcard.com/report/github.com/olahol/melody)\n[![GoDoc](https://godoc.org/github.com/olahol/melody?status.svg)](https://godoc.org/github.com/olahol/melody)\n\n\u003e :notes: Minimalist websocket framework for Go.\n\nMelody is websocket framework based on [github.com/gorilla/websocket](https://github.com/gorilla/websocket)\nthat abstracts away the tedious parts of handling websockets. It gets out of\nyour way so you can write real-time apps. Features include:\n\n* [x] Clear and easy interface similar to `net/http` or Gin.\n* [x] A simple way to broadcast to all or selected connected sessions.\n* [x] Message buffers making concurrent writing safe.\n* [x] Automatic handling of sending ping/pong heartbeats that timeout broken sessions.\n* [x] Store data on sessions.\n\n## Install\n\n```bash\ngo get github.com/olahol/melody\n```\n\n## [Example: chat](https://github.com/olahol/melody/tree/master/examples/chat)\n\n[![Chat](https://cdn.rawgit.com/olahol/melody/master/examples/chat/demo.gif \"Demo\")](https://github.com/olahol/melody/tree/master/examples/chat)\n\n```go\npackage main\n\nimport (\n\t\"net/http\"\n\n\t\"github.com/olahol/melody\"\n)\n\nfunc main() {\n\tm := melody.New()\n\n\thttp.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n\t\thttp.ServeFile(w, r, \"index.html\")\n\t})\n\n\thttp.HandleFunc(\"/ws\", func(w http.ResponseWriter, r *http.Request) {\n\t\tm.HandleRequest(w, r)\n\t})\n\n\tm.HandleMessage(func(s *melody.Session, msg []byte) {\n\t\tm.Broadcast(msg)\n\t})\n\n\thttp.ListenAndServe(\":5000\", nil)\n}\n```\n\n## [Example: gophers](https://github.com/olahol/melody/tree/master/examples/gophers)\n\n[![Gophers](https://cdn.rawgit.com/olahol/melody/master/examples/gophers/demo.gif \"Demo\")](https://github.com/olahol/melody/tree/master/examples/gophers)\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"sync/atomic\"\n\n\t\"github.com/olahol/melody\"\n)\n\nvar idCounter atomic.Int64\n\nfunc main() {\n\tm := melody.New()\n\n\thttp.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n\t\thttp.ServeFile(w, r, \"index.html\")\n\t})\n\n\thttp.HandleFunc(\"/ws\", func(w http.ResponseWriter, r *http.Request) {\n\t\tm.HandleRequest(w, r)\n\t})\n\n\tm.HandleConnect(func(s *melody.Session) {\n\t\tid := idCounter.Add(1)\n\n\t\ts.Set(\"id\", id)\n\n\t\ts.Write([]byte(fmt.Sprintf(\"iam %d\", id)))\n\t})\n\n\tm.HandleDisconnect(func(s *melody.Session) {\n\t\tif id, ok := s.Get(\"id\"); ok {\n\t\t\tm.BroadcastOthers([]byte(fmt.Sprintf(\"dis %d\", id)), s)\n\t\t}\n\t})\n\n\tm.HandleMessage(func(s *melody.Session, msg []byte) {\n\t\tif id, ok := s.Get(\"id\"); ok {\n\t\t\tm.BroadcastOthers([]byte(fmt.Sprintf(\"set %d %s\", id, msg)), s)\n\t\t}\n\t})\n\n\thttp.ListenAndServe(\":5000\", nil)\n}\n```\n\n### [More examples](https://github.com/olahol/melody/tree/master/examples)\n\n## [Documentation](https://godoc.org/github.com/olahol/melody)\n\n## Contributors\n\n\u003ca href=\"https://github.com/olahol/melody/graphs/contributors\"\u003e\n\t\u003cimg src=\"https://contrib.rocks/image?repo=olahol/melody\" /\u003e\n\u003c/a\u003e\n\n## FAQ\n\nIf you are getting a `403` when trying  to connect to your websocket you can [change allow all origin hosts](http://godoc.org/github.com/gorilla/websocket#hdr-Origin_Considerations):\n\n```go\nm := melody.New()\nm.Upgrader.CheckOrigin = func(r *http.Request) bool { return true }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folahol%2Fmelody","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Folahol%2Fmelody","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folahol%2Fmelody/lists"}