{"id":26197424,"url":"https://github.com/golift/subscribe","last_synced_at":"2025-06-20T04:08:02.608Z","repository":{"id":57558903,"uuid":"166947494","full_name":"golift/subscribe","owner":"golift","description":"Go Event Subscription Library","archived":false,"fork":false,"pushed_at":"2025-05-04T23:10:06.000Z","size":59,"stargazers_count":4,"open_issues_count":4,"forks_count":2,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-06-20T04:07:56.430Z","etag":null,"topics":["go-library","subscription-manager","subscriptions"],"latest_commit_sha":null,"homepage":"https://godoc.org/golift.io/subscribe","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/golift.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,"zenodo":null}},"created_at":"2019-01-22T07:23:15.000Z","updated_at":"2024-03-23T16:29:03.000Z","dependencies_parsed_at":"2024-06-21T16:41:36.959Z","dependency_job_id":"befce938-4af2-4782-a2f9-9f787c6c10ba","html_url":"https://github.com/golift/subscribe","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/golift/subscribe","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golift%2Fsubscribe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golift%2Fsubscribe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golift%2Fsubscribe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golift%2Fsubscribe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/golift","download_url":"https://codeload.github.com/golift/subscribe/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golift%2Fsubscribe/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260878463,"owners_count":23075962,"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":["go-library","subscription-manager","subscriptions"],"created_at":"2025-03-12T02:27:02.372Z","updated_at":"2025-06-20T04:07:57.592Z","avatar_url":"https://github.com/golift.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-subscribe\n\nA (mostly generic) Subscription Library for Go.\n\nThis library allows you to subscribe things (like users) to events.\nThe library holds subscribers in memory. It can be also be configured\nto persist subscriptions to disk. The subscription database should scale\nto thousands of subscriptions with hundreds of request per second.\nIf you need more, this library may not work for you; I do not know.\n\nThread safe.\n\nThe following is a very simple example. This library provides many other methods\nnot shown here to deal with event and notification rules, pause/un-pausing, etc.\n\n```golang\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"golift.io/subscribe\"\n)\n\nfunc main() {\n\t// Instantiate an in-memory database. Passing a file-path here loads\n\t// a DB from disk, or saves a new database to the file-path provided.\n\tdb, _ := subscribe.GetDB(\"\")\n\n\t// Create two new subscribers. Initial state has no subscriptions.\n\tnewSub := db.CreateSub(\"you@email.com.tw\", \"smtp\", false, false)\n\tnewSub2 := db.CreateSub(\"+18089117234\", \"sms\", false, false)\n\n\t// Subscribe the users to an event. Errors only if subscription already exists.\n\t_ = newSub.Subscribe(\"party invites\")\n\t_ = newSub2.Subscribe(\"party invites\")\n\n\t// Limit subscriber search to only email recipients. Initial state returns any API.\n\tdb.EnableAPIs = []string{\"smtp\"}\n\n\t// Now that your party invites event has subscribers, you can find them when a party invite arrives.\n\tsubs := db.GetSubscribers(\"party invites\")\n\tfmt.Printf(\"Sending email to %d subscriber(s):\\n\", len(subs))\n\n\tfor _, sub := range subs {\n\t\tfmt.Println(sub.Contact)\n\t\t// send email.\n\t}\n\n\t// Limit subscriber search to only sms.\n\tdb.EnableAPIs[0] = \"sms\"\n\t// Now that your party invites event has subscribers, you can find them when a party invite arrives.\n\tsubs = db.GetSubscribers(\"party invites\")\n\tfmt.Printf(\"Sending Text Msg to %d subscriber(s):\\n\", len(subs))\n\n\tfor _, sub := range subs {\n\t\tfmt.Println(sub.Contact)\n\t\t// send sms.\n\t}\n\n\t// if you want to save the DB:\n\terr := db.StateFileRelocate(\"/var/lib/somewhere/for/a/file.json\")\n\tif err != nil {\n\t\tfmt.Println(\"Unable to relocate DB:\", err)\n\t\treturn\n\t}\n\n\t// save the DB once in a while, or after making changes.\n\tticker := time.NewTicker(time.Minute)\n\tfor range ticker.C {\n\t\terr = db.StateFileSave()\n\t\t// This always returns nil if state file path is empty: \"\"\n\t\tif err != nil {\n\t\t\tfmt.Println(\"Unable to save DB:\", err)\n\t\t}\n\t}\n}\n```\n\nOutput:\n\n```\nSending email to 1 subscriber(s):\nyou@email.com.tw\nSending Text Msg to 1 subscriber(s):\n+18089117234\nUnable to relocate DB: open /var/lib/somewhere/for/a/file.json: no such file or directory\n```\n\nFeedback, ideas and contributions welcomed!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgolift%2Fsubscribe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgolift%2Fsubscribe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgolift%2Fsubscribe/lists"}