{"id":43188713,"url":"https://github.com/christopher-kleine/sse","last_synced_at":"2026-02-01T04:35:59.391Z","repository":{"id":192602202,"uuid":"687148691","full_name":"christopher-kleine/sse","owner":"christopher-kleine","description":"Simple Server Sent Events Library in Go (inspired by Melody)","archived":false,"fork":false,"pushed_at":"2023-09-22T17:01:48.000Z","size":35,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-21T19:01:48.070Z","etag":null,"topics":["eventstream","go","golang","mit-licence","mit-license","server-sent-event","sse","zero-dependency"],"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/christopher-kleine.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":"2023-09-04T18:20:08.000Z","updated_at":"2023-09-12T13:27:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"6e90c234-7c45-4fa2-a06c-2b1665e43f3f","html_url":"https://github.com/christopher-kleine/sse","commit_stats":null,"previous_names":["christopher-kleine/sse"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/christopher-kleine/sse","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christopher-kleine%2Fsse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christopher-kleine%2Fsse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christopher-kleine%2Fsse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christopher-kleine%2Fsse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/christopher-kleine","download_url":"https://codeload.github.com/christopher-kleine/sse/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christopher-kleine%2Fsse/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28968019,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T03:46:10.227Z","status":"ssl_error","status_checked_at":"2026-02-01T03:46:01.693Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["eventstream","go","golang","mit-licence","mit-license","server-sent-event","sse","zero-dependency"],"created_at":"2026-02-01T04:35:59.290Z","updated_at":"2026-02-01T04:35:59.379Z","avatar_url":"https://github.com/christopher-kleine.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SSE - Melody inspired Server Sent Events Library\n\n[![go.dev Reference](https://pkg.go.dev/static/frontend/badge/badge.svg)](https://pkg.go.dev/github.com/christopher-kleine/sse) ![Test Status](https://github.com/christopher-kleine/sse/actions/workflows/test.yml/badge.svg)\n\n## Synopsis\n\nA small library providing easy SSE functionality. The API is inspired by the great WebSocket library [melody](https://github.com/olahol/melody).\n\n**Note:** This library is mainly for my own use and didn't account for other use-cases. If you need something more stable or a more mature library, check [r3labs/sse](https://github.com/r3labs/sse). Same goes for if you want a SSE Client library. But please feel free to tear the source and I'm open for PRs.\n\n## Table of Contents\n\n- [Synopsis](#synopsis)\n- [Features](#feature)\n- [Install](#install)\n- [How to use it](#how-to-use-it)\n- [Filtered/Selected Publish](#filteredselected-publish)\n- [HTML/HTMX Templates](#htmlhtmx-templates)\n- [Using Gin](#using-gin)\n\n## Features\n\n- Zero dependencies\n- [melody](https://github.com/olahol/melody) inspired\n- HTML/HTMX\n- Compatible with standard mux handlers\n\n## Install\n\n```\ngo get github.com/christopher-kleine/sse@latest\n```\n\n## How to use it\n\n```go\npackage main\n\nimport (\n\t\"net/http\"\n\n\t\"github.com/christopher-kleine/sse\"\n)\n\nfunc main() {\n\t// Create a new Hub\n\thub := sse.New()\n\n\t// (Optional): Specify OnConnect and OnDisconnect hooks\n\thub.OnConnect = func(session *sse.Session) {}\n\thub.OnDisconnect = func(session *sse.Session) {}\n\n\t// Specify the endpoint\n\thttp.Handle(\"/sse\", hub)\n\n\t// (Optional): Customize the request\n\t/*\n\thttp.HandleFunc(\"/sse\", func(w http.Response, r *http.Request) {\n\t\tw.Header().Set(\"Access-Control-Allow-Origin\", \"*\")\n\t\thub.ServeHTTP(w, r)\n\t})\n\t*/\n\n\t// Publish some data!\n\tgo func() {\n\t\tfor {\n\t\t\thub.Publish(\u0026sse.Event{ Data: \"Hello World\" })\n\t\t\ttime.Sleep(1 * time.Second)\n\t\t}\n\t}()\n\n\thttp.ListenAndServe(\":8080\", nil)\n}\n```\n\n## Filtered/Selected Publish\n\nYou can also publish to selected sessions.\n\n```go\n// Only sent to users we gave the \"villain\" role.\nev := \u0026sse.Event{Data: \"Hello, Villain. What are your next plans?\"}\nhub.FilteredPublish(ev, func(session *sse.Session) bool {\n\treturn session.Get(\"role\") == \"villain\"\n})\n```\n\n## HTML/HTMX Templates\n\nYou can use this library to send HTML templates over SSE, since the `Event` type implements the `io.Writer` Interface:\n\n```go\nev := \u0026sse.Event{}\ntemplates.ExecuteTemplate(ev, \"index.html\", nil)\nhub.Publish(ev)\n```\n\n## Using Gin\n\nThe popular web framework [Gin](https://gin-gonic.com/) can be used too:\n\n```go\npackage main\n\nimport (\n\t\"net/http\"\n\t\"time\"\n\n\t\"github.com/christopher-kleine/sse\"\n\t\"github.com/gin-gonic/gin\"\n)\n\nfunc main() {\n\thub := sse.New()\n\n\tgo func() {\n\t\thub.Publish(\u0026sse.Event{ Data: \"ping\" })\n\t\ttime.Sleep(2 * time.Second)\n\t}()\n\n\tr := gin.Default()\n\tr.GET(\"/sse\", func(c *gin.Context) {\n\t\thub.ServeHTTP(c.Writer, c.Request)\n\t})\n\tr.Run()\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristopher-kleine%2Fsse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchristopher-kleine%2Fsse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristopher-kleine%2Fsse/lists"}