{"id":13413405,"url":"https://github.com/jcuga/golongpoll","last_synced_at":"2026-01-16T23:24:51.125Z","repository":{"id":41277090,"uuid":"45363664","full_name":"jcuga/golongpoll","owner":"jcuga","description":"golang long polling library.  Makes web pub-sub easy via HTTP long-poll servers and clients :smiley: :coffee: :computer:","archived":false,"fork":false,"pushed_at":"2023-08-20T19:40:52.000Z","size":328,"stargazers_count":655,"open_issues_count":0,"forks_count":59,"subscribers_count":23,"default_branch":"master","last_synced_at":"2024-10-25T05:23:21.747Z","etag":null,"topics":["go","golang","golang-library","longpoll","longpoll-api","longpoll-requests","longpoller","longpolling","pubsub","pubsub-publisher","pubsub-subscriber"],"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/jcuga.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}},"created_at":"2015-11-02T00:32:56.000Z","updated_at":"2024-10-14T06:54:20.000Z","dependencies_parsed_at":"2024-01-08T15:34:41.248Z","dependency_job_id":null,"html_url":"https://github.com/jcuga/golongpoll","commit_stats":{"total_commits":157,"total_committers":7,"mean_commits":"22.428571428571427","dds":0.5222929936305732,"last_synced_commit":"e29e4d0e0bba0354f534a523f08eb0f9ef8a9137"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/jcuga/golongpoll","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcuga%2Fgolongpoll","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcuga%2Fgolongpoll/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcuga%2Fgolongpoll/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcuga%2Fgolongpoll/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jcuga","download_url":"https://codeload.github.com/jcuga/golongpoll/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcuga%2Fgolongpoll/sbom","scorecard":{"id":512012,"data":{"date":"2025-08-11","repo":{"name":"github.com/jcuga/golongpoll","commit":"223792742fa752d16c9c6ba075dbb1e7ac38bae2"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/11 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/main.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":3,"reason":"dependency not pinned by hash detected -- score normalized to 3","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/jcuga/golongpoll/main.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/jcuga/golongpoll/main.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:37: update your workflow using https://app.stepsecurity.io/secureworkflow/jcuga/golongpoll/main.yml/master?enable=pin","Warn: goCommand not pinned by hash: .github/workflows/main.yml:24","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned","Info:   1 out of   2 goCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 22 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-20T00:48:22.791Z","repository_id":41277090,"created_at":"2025-08-20T00:48:22.792Z","updated_at":"2025-08-20T00:48:22.792Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28487586,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T22:54:02.790Z","status":"ssl_error","status_checked_at":"2026-01-16T22:50:10.344Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":["go","golang","golang-library","longpoll","longpoll-api","longpoll-requests","longpoller","longpolling","pubsub","pubsub-publisher","pubsub-subscriber"],"created_at":"2024-07-30T20:01:39.577Z","updated_at":"2026-01-16T23:24:51.103Z","avatar_url":"https://github.com/jcuga.png","language":"Go","funding_links":[],"categories":["Messaging","消息","消息系统","\u003cspan id=\"消息-messaging\"\u003e消息 Messaging\u003c/span\u003e","Relational Databases","消息传递","机器学习","Go","Web Frameworks"],"sub_categories":["Search and Analytic Databases","检索及分析资料库","Advanced Console UIs","SQL 查询语句构建库","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","交流"],"readme":"# golongpoll ![build workflow](https://github.com/jcuga/golongpoll/actions/workflows/main.yml/badge.svg) [![codecov](https://codecov.io/gh/jcuga/golongpoll/branch/master/graph/badge.svg)](https://codecov.io/gh/jcuga/golongpoll)  [![GoDoc](https://godoc.org/github.com/jcuga/golongpoll?status.svg)](https://godoc.org/github.com/jcuga/golongpoll) [![Go Report Card](https://goreportcard.com/badge/jcuga/golongpoll)](https://goreportcard.com/report/jcuga/golongpoll)\nGolang long polling library. Makes web pub-sub easy via HTTP long-poll servers and clients.\n\n## Resources\n* [go docs](https://pkg.go.dev/github.com/jcuga/golongpoll)\n* [examples](/examples/README.md) - shows how to use the longpoll server and go/js clients.\n* [go client](/client/README.md)\n* [javascript client](/js-client/README.md)\n* [longpoll http api](/HttpLongPollAPI.md) - in case you want to create your own client.\n* [longpoll with gin apps](#long-polling-and-gin)\n\n## QuickStart\nTo create a longpoll server:\n```go\nimport (\n  \"github.com/jcuga/golongpoll\"\n)\n\n// This uses the default/empty options. See section on customizing, and Options go docs.\nmanager, err := golongpoll.StartLongpoll(golongpoll.Options{})\n\n// Expose pub-sub. You could omit the publish handler if you don't want\n// to allow clients to publish. For example, if clients only subscribe to data.\nif err == nil {\n  http.HandleFunc(\"/events\", manager.SubscriptionHandler)\n  http.HandleFunc(\"/publish\", manager.PublishHandler)\n  http.ListenAndServe(\"127.0.0.1:8101\", nil)\n} else {\n  // handle error creating longpoll manager--typically this means a bad option.\n}\n```\n\nThe above snippet will create a [LongpollManager](https://pkg.go.dev/github.com/jcuga/golongpoll#LongpollManager) which has a `SubscriptionHandler` and a `PublishHandler` that can served via http (or using https).  When created, the manager spins up a separate goroutine that handles the plumbing for pub-sub.\n\n`LongpollManager` also has a [Publish](https://pkg.go.dev/github.com/jcuga/golongpoll#LongpollManager.Publish) function that can be used to publish events. You can call `manager.Publish(\"some-category\", \"some data here\")` and/or expose the `manager.PublishHandler` and allow publishing of events via the [longpoll http api](/HttpLongPollAPI.md).  For publishing within the same program as the manager/server, calling `manager.Publish()` does not use networking--under the hood it uses the go channels that are part of the pub-sub plumbing.  You could also wrap the manager in an http handler closure that calls publish as desired.\n\nSee the [Examples](/examples/README.md) on how to use the golang and javascript clients as well as how to wrap the `manager.PublishHandler` or call `manager.Publish()` directly.\n\n## How it Works\nYou can think of the longpoll manager as a goroutine that uses channels to service pub-sub requests.  The manager has a `map[string]eventBuffer` (actually a `map[string]*expiringBuffer`) that holds events per category as well as a data structure (another sort of map) for the subscription request book-keeping.  The `PublishHandler` and `SubscribeHandler` interact with the manager goroutine via channels.\n\nThe events are stored using in-memory buffers that have a configured max number of events per category.  Optionally, the events can be automatically removed based on a time-to-live setting.  Since this is all in-memory, there is an optional add-on for auto-persisting and repopulating data from disk.  This allows events to persist across program restarts (not the default option/behavior!) One can also create their own custom add-on as well.  See the `Customizing` section.\n\nOne important limitation/design-decision to be aware of: the `SubscriptionHandler` supports subscribing to a *single cateogry*.  If you want to subscribe to more than one category, you must make more than one call to the subscription handler--or create multiple clients each with a different category.  Note however that clients are free to publish to more than one categor--to any category really, unless the manager's publish handler is not being served or there is wrapping handler logic that forbids this.  Whether or not this limitation is a big deal depends on how you are using categories. This decision reduces the internal complexity and is likely not to change any time soon. \n\n## Customizing\nSee [golongpoll.Options](https://pkg.go.dev/github.com/jcuga/golongpoll#Options) on how to configure the longpoll manager.  This includes:\n* `MaxEventBufferSize` - for the max number of events per category, after which oldest-first is truncated. Defaults to 250.\n* `EventTimeToLiveSeconds` - how long events exist in the buffer, defaults to forever (as long as `MaxEventBufferSize` isn't reached).\n* `AddOn` - optional way to provide custom behavior. The only add-on at the moment is [FilePersistorAddOn](/fileaddon.go) (Usage [example](/examples/filepersist/filepersist.go)). See [AddOn interface](/addons.go) for creating your own custom add-on.\n\nRemember, you don't have to expose `LongpollManager.SubscriptionHandler` and `PublishHandler` directly (or at all).  You can wrap them with your own http handler that adds additional logic or validation before invoking the inner handler.  See the [authentication example](/examples/authentication/auth.go) for how to require auth via header data before those handlers get called.  For publishing, you can also call `manager.Publish()` directly, or wrap the manager via a closure to create a custom http handler that publishes data.\n\n# long polling and gin\n\nNeed to add long polling to a Gin HTTP Framework app?  Simply wrap golongpoll's manager pub/sub functions with a `gin.Context` and pass to `router.POST` and `router.GET`:\n\n```go\npackage main\n\nimport (\n\t\"net/http\"\n\n\t\"github.com/gin-gonic/gin\"\n\n\t\"github.com/jcuga/golongpoll\"\n)\n\nfunc main() {\n\t// Create longpoll manger with default opts\n\tmanager, err := golongpoll.StartLongpoll(golongpoll.Options{})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\trouter := gin.Default()\n\trouter.POST(\"/pub\", wrapWithContext(manager.PublishHandler))\n\trouter.GET(\"/sub\", wrapWithContext(manager.SubscriptionHandler))\n\trouter.Run(\":8001\")\n}\n\nfunc wrapWithContext(lpHandler func(http.ResponseWriter, *http.Request)) func(*gin.Context) {\n\treturn func(c *gin.Context) {\n\t\tlpHandler(c.Writer, c.Request)\n\t}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcuga%2Fgolongpoll","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjcuga%2Fgolongpoll","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcuga%2Fgolongpoll/lists"}