{"id":37091673,"url":"https://github.com/vandathron/pub","last_synced_at":"2026-01-14T11:09:35.903Z","repository":{"id":59045730,"uuid":"530825258","full_name":"Vandathron/pub","owner":"Vandathron","description":"A go package based on the publish/subscribe model to execute independently executing functions,tasks or subscribers by sending events to its subscribers","archived":false,"fork":false,"pushed_at":"2022-10-04T11:59:54.000Z","size":11,"stargazers_count":13,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-28T02:45:50.134Z","etag":null,"topics":["concurrency","go","golang","pubsub"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Vandathron.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-30T20:47:19.000Z","updated_at":"2022-09-14T22:36:28.000Z","dependencies_parsed_at":"2023-01-19T05:15:19.783Z","dependency_job_id":null,"html_url":"https://github.com/Vandathron/pub","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Vandathron/pub","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vandathron%2Fpub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vandathron%2Fpub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vandathron%2Fpub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vandathron%2Fpub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Vandathron","download_url":"https://codeload.github.com/Vandathron/pub/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vandathron%2Fpub/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28417962,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","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":["concurrency","go","golang","pubsub"],"created_at":"2026-01-14T11:09:35.004Z","updated_at":"2026-01-14T11:09:35.898Z","avatar_url":"https://github.com/Vandathron.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vandathron/pub\n\nPackage `vandathron/pub` is designed based on the publish/subscribe model to \nexecute independently executing functions,tasks or subscribers by sending events to its subscribers. \nMain Features:\n\n* Event creation. Events can be created by calling the CreateEvent method\n* Registering/Unregistering subscribers to events\n* Configurable logging. Interface `Logger` can be implemented to configure logging\n* Simple Concurrent execution of subscribers\n\n---\n\n* [Install](#install)\n* [Examples](#examples)\n* [Full Example](#full-example)\n\n## Install\n\nWith [go](https://go.dev/doc/install) installed, you can install this package with this command\n\n```sh\ngo get -u github.com/vandathron/pub\n```\n\n---\n## Examples\n\nLet's start by creating a publisher with a single event\n\n```go\nfunc main() {\n\tp := pub.NewPublisher()\n\tp.CreateEvent(\"USER.CREATED\")\n}\n```\n\nWe can then declare subscribers, listeners or functions. Parameter must conform with the example below\n```go\nfunc SendWelcomeEmail(data pub.EventPayload){\n    u := data.Data.(User)\n    fmt.Println(u.name)\n    fmt.Println(\"Sending welcome mail..\")\n    ...\n}\n\nfunc SendSMS(data pub.EventPayload){\n    u := data.Data.(User)\n    fmt.Println(u.name)\n    fmt.Println(\"Sending phone message..\")\n    ...\n}\n```\nSubscribe listeners to event:\n```go\np.Subscribe(\"USER.CREATED\", SendSMS, SendWelcomeEmail)\n ```\n6\nEvent can be emitted by calling `Publish(event string)` method. This publishes event and execute subscribers concurrently.\n\n```go\np.Publish(\"USER.CREATED\", pub.EventPayload{\n    Data:   User{name: \"van\"},\n    Header: pub.Header{},\n})\n```\n\nListeners can be unsubscribed from an event:\n```go\np.Unsubscribe(SendSMS, \"USER.CREATED\")\n```\nLogging is disabled by default. We can create a logger that implements the `Logger` interface.\n\n```go\ntype EvtLogger struct {\n\n}\n\nfunc (e *EvtLogger) LogInfo(msg string) {\n    ...\n}\n\nfunc (e *EvtLogger) LogErr(msg string) {\n    ...\n}\n```\n\nLogging can now be enabled \n```go\np.DisableLogs = false\np.SetLogger(\u0026EvtLogger)\n```\n---\n## Full Example\n\n```go\ntype EvtLogger struct {\n\n}\n\nvar _ pub.Logger = new(EvtLogger)\n\nfunc (e EvtLogger) LogInfo(msg string) {\n   \n}\n\nfunc (e EvtLogger) LogErr(msg string) {\n    \n}\n\ntype User struct {\n    name string\n}\n\nfunc main(){\n\tp := pub.NewPublisher()\n\tp.DisableLogs = false;\n\tp.SetLogger(\u0026EvtLogger{})\n\t\n\tp.CreateEvent(\"USER.CREATED\")\n\tp.CreateEvent(\"USER.DELETED\")\n\n\tp.Subscribe(\"USER.CREATED\", SendSMS)\n    p.Subscribe(\"USER.CREATED\", SendWelcomeEmail)\n\n\tp.Publish(\"USER.CREATED\", pub.EventPayload{\n\t\tData:   User{name: \"van\"},\n\t\tHeader: pub.Header{},\n\t})\n\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvandathron%2Fpub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvandathron%2Fpub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvandathron%2Fpub/lists"}