{"id":13413603,"url":"https://github.com/lampctl/go-sse","last_synced_at":"2025-03-14T19:32:51.198Z","repository":{"id":65169992,"uuid":"582842794","full_name":"lampctl/go-sse","owner":"lampctl","description":"Go package for sending and receiving SSE (server-sent events)","archived":false,"fork":false,"pushed_at":"2023-05-21T04:40:03.000Z","size":42,"stargazers_count":9,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-07-31T20:52:36.235Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lampctl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-12-28T02:43:05.000Z","updated_at":"2024-07-08T06:45:54.000Z","dependencies_parsed_at":"2024-01-08T15:34:48.059Z","dependency_job_id":null,"html_url":"https://github.com/lampctl/go-sse","commit_stats":{"total_commits":19,"total_committers":1,"mean_commits":19.0,"dds":0.0,"last_synced_commit":"e677e67f89e92b36b2067cd0c2b9f95ddcf93eb6"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lampctl%2Fgo-sse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lampctl%2Fgo-sse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lampctl%2Fgo-sse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lampctl%2Fgo-sse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lampctl","download_url":"https://codeload.github.com/lampctl/go-sse/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221498771,"owners_count":16833059,"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-07-30T20:01:44.259Z","updated_at":"2024-10-26T05:31:11.865Z","avatar_url":"https://github.com/lampctl.png","language":"Go","readme":"## go-sse\n\n[![Build Status](https://github.com/lampctl/go-sse/actions/workflows/test.yml/badge.svg)](https://github.com/lampctl/go-sse/actions/workflows/test.yml)\n[![Coverage Status](https://coveralls.io/repos/github/lampctl/go-sse/badge.svg?branch=main)](https://coveralls.io/github/lampctl/go-sse?branch=main)\n[![Go Report Card](https://goreportcard.com/badge/github.com/lampctl/go-sse)](https://goreportcard.com/report/github.com/lampctl/go-sse)\n[![Go Reference](https://pkg.go.dev/badge/github.com/lampctl/go-sse.svg)](https://pkg.go.dev/github.com/lampctl/go-sse)\n[![MIT License](https://img.shields.io/badge/license-MIT-9370d8.svg?style=flat)](https://opensource.org/licenses/MIT)\n\nThis package attempts to provide a robust and reliable implementation of [server-sent events](https://html.spec.whatwg.org/multipage/server-sent-events.html#concept-event-stream-reconnection-time). One might use this package if they were writing an application that needed to connect to an SSE server endpoint and read events in a continuous stream or provide events to a front-end service.\n\n### Features\n\nHere's what you get with this package:\n\n- Complete documentation for every last type and method in the package\n- Compliancy with section 9.2 of the WHATWG HTML specification\n- Extensive test suite to ensure conformance\n\ngo-sse requires a minimum of **Go 1.18**.\n\n### Basic Usage\n\nTo use the package in your application, begin by importing it:\n\n```golang\nimport \"github.com/lampctl/go-sse\"\n```\n\n### Use as a Client\n\nCreate a client using:\n\n```golang\nc, err := sse.NewClientFromURL(\"http://example.com/sse\")\nif err != nil {\n    // ...\n}\n```\n\nYou can now read events directly from the `c.Events` channel as they are received:\n\n```golang\nfor e := range c.Events {\n    fmt.Println(\"Event received!\")\n    fmt.Println(e.Data)\n}\n```\n\n\u003e Note that if the connection is closed or interrupted, the client will attempt to reconnect as per the spec and continue returning events from where it was interrupted. This is all handled behind the scenes and won't affect the status of the event channel.\n\nWhen you are done receiving events, close the client:\n\n```golang\nc.Close()\n```\n\n### Use as a Server\n\nThe server component is provided via `Handler`, which implements `http.Handler`:\n\n```golang\nh := sse.NewHandler(nil)\n\n// ...or if you want to customize initialization:\nh := sse.NewHandler(\u0026sse.HandlerConfig{\n    NumEventsToKeep:   10,\n    ChannelBufferSize: 4,\n})\n```\n\nTo send an event, simply use the `Send()` method:\n\n```golang\nh.Send(\u0026sse.Event{\n    Type: \"alert\",\n    Data: \"The aliens are invading!\",\n    ID:   \"12345\",\n})\n```\n\nWhen you are done, use the `Close()` method:\n\n```golang\nh.Close()\n```\n","funding_links":[],"categories":["网络","Networking"],"sub_categories":["音译","Transliteration"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flampctl%2Fgo-sse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flampctl%2Fgo-sse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flampctl%2Fgo-sse/lists"}