{"id":25487030,"url":"https://github.com/eighty4/sse","last_synced_at":"2025-06-10T08:34:15.527Z","repository":{"id":57549622,"uuid":"196647665","full_name":"eighty4/sse","owner":"eighty4","description":null,"archived":false,"fork":false,"pushed_at":"2021-12-05T00:24:47.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-05-18T17:52:59.133Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/eighty4.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":"2019-07-12T21:20:45.000Z","updated_at":"2023-01-22T21:31:40.000Z","dependencies_parsed_at":"2022-08-27T00:40:34.054Z","dependency_job_id":null,"html_url":"https://github.com/eighty4/sse","commit_stats":null,"previous_names":["eighty4/gosse"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eighty4%2Fsse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eighty4%2Fsse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eighty4%2Fsse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eighty4%2Fsse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eighty4","download_url":"https://codeload.github.com/eighty4/sse/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eighty4%2Fsse/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259038369,"owners_count":22796609,"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":"2025-02-18T19:34:51.228Z","updated_at":"2025-06-10T08:34:15.498Z","avatar_url":"https://github.com/eighty4.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Go Reference](https://pkg.go.dev/badge/github.com/eighty4/sse.svg)](https://pkg.go.dev/github.com/eighty4/sse)\n\n## SSE Upgrade\n\nThis library exports a func that upgrades http requests to an event streaming connection by sending a `Content-Type: text/event-stream` header to the client.\n```go\nhttp.HandleFunc(\"/\", func (w http.ResponseWriter, r *http.Request) {\n    var connection *sse.Connection\n    connection, _ = sse.Upgrade(w, r)\n    connection.SendString(\"thanks for connecting. here's some data.\")\n    connection.Close()\n})\n```\n\nConnection's `SendBytes([]byte)`, `SendString(string)` and `SendJson(interface{})` funcs will format and send data to the client.\n\nUse `Close()` when you're done streaming event data.\n\nA connection's BuildMessage() func can be used to send a payload with the id and event attributes.\n```go\nconnection.BuildMessage().WithId(\"id\").WithEvent(\"event\").SendString(\"data\")\n```\nThis message will be sent to the client:\n```text\nid: id\nevent: event\ndata: data\n\n```\n\n### Example\n```go\npackage main\n\nimport (\n\t\"github.com/eighty4/sse\"\n\t\"log\"\n\t\"net/http\"\n)\n\nfunc handler(w http.ResponseWriter, r *http.Request) {\n\tconnection, err := sse.Upgrade(w, r)\n\tif err != nil {\n\t\tw.WriteHeader(500)\n\t\tlog.Println(\"sse upgrade error\", err.Error())\n\t\treturn\n\t}\n\tconnection.BuildMessage().WithEvent(\"auth\").SendString(\"token\")\n\tconnection.Close()\n}\n\nfunc main() {\n\thttp.HandleFunc(\"/\", handler)\n\tlog.Fatal(http.ListenAndServe(\":8080\", nil))\n}\n```\n\n#### Original Repository\nI found originating source for sse.go on GitHub a couple of years ago, but I couldn't find the repository to reference when publishing updates.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feighty4%2Fsse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feighty4%2Fsse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feighty4%2Fsse/lists"}