{"id":21966703,"url":"https://github.com/4strodev/events","last_synced_at":"2025-06-11T19:07:15.479Z","repository":{"id":199655581,"uuid":"703419494","full_name":"4strodev/events","owner":"4strodev","description":"A simple event service written in go","archived":false,"fork":false,"pushed_at":"2023-10-11T09:54:56.000Z","size":18,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-22T21:46:48.512Z","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/4strodev.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}},"created_at":"2023-10-11T07:58:34.000Z","updated_at":"2023-10-12T02:30:42.000Z","dependencies_parsed_at":"2023-10-11T11:27:32.412Z","dependency_job_id":null,"html_url":"https://github.com/4strodev/events","commit_stats":null,"previous_names":["4strodev/events"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/4strodev/events","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/4strodev%2Fevents","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/4strodev%2Fevents/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/4strodev%2Fevents/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/4strodev%2Fevents/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/4strodev","download_url":"https://codeload.github.com/4strodev/events/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/4strodev%2Fevents/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259320409,"owners_count":22839978,"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-11-29T13:17:51.460Z","updated_at":"2025-06-11T19:07:15.462Z","avatar_url":"https://github.com/4strodev.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Events\nThis is a simple event service that allows you to emit events, listen events using glob regex to match event names. Destroy event listeners. It is context aware and allows you to use it for graceful shutdown.\n\n## Installation\n```sh\ngo get github.com/4strodev/events@latest\n```\n\n## Usage\nLoggin example\n```go\npackage main\n\nimport (\n    \"log\"\n    \"sync\"\n    \"context\"\n    \"github.com/4strodev/events/pkg\"\n)\n\nfunc main() {\n    // Create new event serivce with default configuration\n    eventService := events.NewEventService()\n    // The waitgroup will be used only in this example\n    // In real applications normally the main goroutine is locked by a server, GUI, etc.\n    waitGroup := sync.WaitGroup{}\n    \n    // You decide when to start the service\n    // Note! You can add listeners before start the service.\n    // The start method simply starts to process events from event queue\n    eventService.Start()\n\n    waitGroup.Add(1)\n    // Here we will implement a simple loggin system using events\n    eventService.Listen(\"*\", func(event events.Event) error {\n        defer waitGroup.Done()\n        select {\n        // Note that the Event interface provide a context to allow you to end task if the service is stopped\n        // this is recomended for those tasks that has external connections:\n        // message brokers, databases, external APIs, etc.\n        case \u003c-event.Ctx().Done():\n            return context.Cause(event.Ctx())\n        default:\n            log.Println(event.Tag())\n            log.Println(event.CreatedAt())\n            log.Println(event.Payload())\n            return  nil\n        }\n    })\n\n    event := events.NewBaseEvent(\"event\")\n    eventService.Emit(event.WithPayload(\"A simple payload\"))\n\n    waitGroup.Wait()\n\n    // Also you decide when to stop listening events\n    // Note! When you stop the event service you cannot start it again. This method exist for graceful shutdowns\n    eventService.Stop()\n}\n```\n\n## More information\n[Go doc](https://pkg.go.dev/github.com/4strodev/events)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F4strodev%2Fevents","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F4strodev%2Fevents","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F4strodev%2Fevents/lists"}