{"id":26723014,"url":"https://github.com/shiwano/websocket-conn","last_synced_at":"2025-06-13T02:33:48.623Z","repository":{"id":57525972,"uuid":"65651851","full_name":"shiwano/websocket-conn","owner":"shiwano","description":":telephone_receiver: A dead simple WebSocket connection written in Go.","archived":false,"fork":false,"pushed_at":"2021-01-21T02:11:38.000Z","size":49,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-14T06:55:50.320Z","etag":null,"topics":["golang","websocket"],"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/shiwano.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}},"created_at":"2016-08-14T05:41:06.000Z","updated_at":"2021-01-21T02:11:40.000Z","dependencies_parsed_at":"2022-09-26T18:11:04.505Z","dependency_job_id":null,"html_url":"https://github.com/shiwano/websocket-conn","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/shiwano/websocket-conn","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shiwano%2Fwebsocket-conn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shiwano%2Fwebsocket-conn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shiwano%2Fwebsocket-conn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shiwano%2Fwebsocket-conn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shiwano","download_url":"https://codeload.github.com/shiwano/websocket-conn/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shiwano%2Fwebsocket-conn/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259567200,"owners_count":22877659,"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":["golang","websocket"],"created_at":"2025-03-27T20:39:09.895Z","updated_at":"2025-06-13T02:33:48.606Z","avatar_url":"https://github.com/shiwano.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# websocket-conn [![Build Status](https://secure.travis-ci.org/shiwano/websocket-conn.png?branch=master)](http://travis-ci.org/shiwano/websocket-conn)\n\n\u003e :telephone_receiver: A dead simple WebSocket connection written in Go.\n\nwebsocket-conn provides you with easy handling for WebSockets, it's based on [github.com/gorilla/websocket](https://github.com/gorilla/websocket).\n\n## Installation\n\n```bash\n$ go get -u github.com/shiwano/websocket-conn/v4\n```\n\n## Usage\n\n```go\nfunc Connect(ctx context.Context, settings Settings, url string, requestHeader http.Header) (*Conn *http.Response, error)\nfunc UpgradeFromHTTP(ctx context.Context, settings Settings, w http.ResponseWriter, r *http.Request) (*Conn, error)\n\ntype Conn struct {\n  Stream() \u003c-chan Message\n  Err() error\n  SendBinaryMessage(data []byte) error\n  SendTextMessage(text string) error\n  SendJSONMessage(v interface{}) error\n  Close() error\n}\n```\n\n## Examples\n\nServer:\n\n```go\npackage main\n\nimport (\n  \"context\"\n  \"net/http\"\n  wsconn \"github.com/shiwano/websocket-conn/v4\"\n)\n\nfunc main() {\n  http.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n    c, _ := wsconn.UpgradeFromHTTP(r.Context(), wsconn.DefaultSettings(), w, r)\n\n    for m := range c.Stream() {\n      switch t := m.Text(); t {\n      case \"Hello\":\n        if err := c.SendTextMessage(t + \" World\"); err != nil {\n          log.Fatal(err)\n        }\n      case \"Close\":\n        c.Close()\n      }\n    }\n  })\n  http.ListenAndServe(\":5000\", nil)\n}\n```\n\nClient:\n\n```go\npackage main\n\nimport (\n  \"context\"\n  \"log\"\n  wsconn \"github.com/shiwano/websocket-conn/v4\"\n)\n\nfunc main() {\n  ctx, cancel := context.WithCancel(context.Background())\n  defer cancel()\n\n  c, _, _ := wsconn.Connect(ctx, wsconn.DefaultSettings(), \"ws://localhost:5000\", nil)\n\n  c.SendTextMessage(\"Hello\")\n  m := \u003c-c.Stream()\n  log.Println(m.Text()) // Output: Hello World\n  c.SendTextMessage(\"Close\")\n\n  for range c.Stream() {\n    // wait for closing.\n  }\n}\n```\n\nSee also examples directory.\n\n## License\n\nCopyright (c) 2016 Shogo Iwano\nLicensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshiwano%2Fwebsocket-conn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshiwano%2Fwebsocket-conn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshiwano%2Fwebsocket-conn/lists"}