{"id":20932917,"url":"https://github.com/jferrl/go-event","last_synced_at":"2026-05-26T17:32:50.105Z","repository":{"id":213986956,"uuid":"735378340","full_name":"jferrl/go-event","owner":"jferrl","description":"Simple event handling library written in Go","archived":false,"fork":false,"pushed_at":"2023-12-30T10:11:26.000Z","size":17,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-26T06:49:05.733Z","etag":null,"topics":["events","go","golang"],"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/jferrl.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}},"created_at":"2023-12-24T17:40:49.000Z","updated_at":"2024-01-15T09:20:04.000Z","dependencies_parsed_at":"2024-11-18T21:54:05.640Z","dependency_job_id":"13fedac7-687c-4daf-ba40-c9438aeeab89","html_url":"https://github.com/jferrl/go-event","commit_stats":null,"previous_names":["jferrl/go-event"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/jferrl/go-event","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jferrl%2Fgo-event","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jferrl%2Fgo-event/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jferrl%2Fgo-event/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jferrl%2Fgo-event/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jferrl","download_url":"https://codeload.github.com/jferrl/go-event/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jferrl%2Fgo-event/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33532058,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"ssl_error","status_checked_at":"2026-05-26T15:22:15.568Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":["events","go","golang"],"created_at":"2024-11-18T21:53:45.413Z","updated_at":"2026-05-26T17:32:50.081Z","avatar_url":"https://github.com/jferrl.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-event\n\n[![GoDoc](https://img.shields.io/static/v1?label=godoc\u0026message=reference\u0026color=blue)](https://pkg.go.dev/github.com/jferrl/go-event)\n[![Test Status](https://github.com/jferrl/go-event/workflows/tests/badge.svg)](https://github.com/jferrl/go-event/actions?query=workflow%3Atests)\n[![codecov](https://codecov.io/gh/jferrl/go-event/branch/main/graph/badge.svg?token=68I4BZF235)](https://codecov.io/gh/jferrl/go-event)\n[![Go Report Card](https://goreportcard.com/badge/github.com/jferrl/go-event)](https://goreportcard.com/report/github.com/jferrl/go-event)\n\nGo simple (zero deps) library for event handling. The main goal of this library is to provide a simple and easy to use event handling system with a minimal footprint within a Go application. This library is inspired by Node.js [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter).\n\n## Usage\n\ngo-event is compatible with modern Go releases.\nThis pkg use Go generics, so you need to use Go 1.18 or later.\n\nTake into account that each event listener is executed in a goroutine, so you need to take care with race conditions.\n\n```go\npackage main\n\nimport (\n \"context\"\n \"log\"\n \"os\"\n \"time\"\n\n \"github.com/jferrl/go-event\"\n)\n\nconst (\n // UserCreated .\n UserCreated event.Event = \"user.created\"\n // UserDeleted .\n UserDeleted event.Event = \"user.deleted\"\n // UserUpdated .\n UserUpdated event.Event = \"user.updated\"\n)\n\n// UserEvent .\ntype UserEvent struct {\n ID string\n}\n\nfunc main() {\n logger := log.New(os.Stdout, \"go-event: \", log.LstdFlags)\n\n ctx := context.Background()\n\n emitter := event.NewEmitter[UserEvent]()\n\n emitter.\n  On(UserCreated, func(ctx context.Context, data UserEvent) {\n   // handle user created event\n   logger.Printf(\"user created: %s\", data.ID)\n  }).\n  On(UserDeleted, func(ctx context.Context, data UserEvent) {\n   // handle user deleted event\n   logger.Printf(\"user deleted: %s\", data.ID)\n  }).\n  On(UserUpdated,\n   func(ctx context.Context, data UserEvent) {\n    // handle user updated event\n    logger.Printf(\"user updated: %s\", data.ID)\n   },\n   func(ctx context.Context, data UserEvent) {\n    // other event listener for the same event.\n    logger.Printf(\"making some actions with user: %s\", data.ID)\n   },\n  )\n\n emitter.Emit(ctx, UserCreated, UserEvent{ID: \"1\"})\n emitter.Emit(ctx, UserDeleted, UserEvent{ID: \"2\"})\n emitter.Emit(ctx, UserUpdated, UserEvent{ID: \"3\"})\n\n time.Sleep(1 * time.Second)\n}\n```\n\nIf you need to execute the event listeners synchronously, you can set SyncEmitter option.\n\n```go\npackage main\n\nimport \"github.com/jferrl/go-event\"\n\n// UserEvent .\ntype UserEvent struct {\n ID string\n}\n\nfunc main() {\n emitter := event.NewEmitter[UserEvent](event.SyncEmitter[UserEvent])\n}\n```\n\n## Bootstrap complex event listeners\n\nIn some scenarios, you may need to bootstrap complex event listeners. For example, the listerner\nhas several dependencies, like a logger, a database connection, etc. In this case, you can use a\nfunction to bootstrap the event listener and pass the dependencies to it.\n\n```go\npackage main\n\nimport (\n \"context\"\n \"log\"\n \"os\"\n \"time\"\n\n \"github.com/jferrl/go-event\"\n)\n\n// UserCreated .\nconst UserCreated event.Event = \"user.created\"\n\n// UserEvent .\ntype UserEvent struct {\n ID string\n}\n\n// EmailClient handles the email scheduling.\ntype EmailClient struct{}\n\n// Schedule schedules an email to be sent to the user.\nfunc (e *EmailClient) Schedule(_ context.Context, _ string) error {\n return nil\n}\n\n// EmailScheduler handles the email scheduling.\ntype EmailScheduler interface {\n Schedule(ctx context.Context, userID string) error\n}\n\n// Logger handles the logging.\ntype Logger interface {\n Printf(format string, v ...interface{})\n}\n\n// BootstrapEmailSheduleHandler bootstraps the email scheduler handler\n// Handler will be called when user created event is emitted.\n// It will schedule an email to be sent to the user.\nfunc BootstrapEmailSheduleHandler(logger Logger, s EmailScheduler) event.Listerner[UserEvent] {\n return func(ctx context.Context, data UserEvent) {\n  // handle user created event\n  logger.Printf(\"user created: %s\", data.ID)\n\n  // schedule email\n  if err := s.Schedule(ctx, data.ID); err != nil {\n   logger.Printf(\"failed to schedule email: %v\", err)\n  }\n }\n}\n\nfunc main() {\n logger := log.New(os.Stdout, \"go-event: \", log.LstdFlags)\n e := \u0026EmailClient{}\n\n ctx := context.Background()\n\n emitter := event.NewEmitter[UserEvent]()\n\n emitter.On(UserCreated, BootstrapEmailSheduleHandler(logger, e))\n\n emitter.Emit(ctx, UserCreated, UserEvent{ID: \"1\"})\n\n time.Sleep(1 * time.Second)\n}\n```\n\n## License\n\nThis library is distributed under the MIT license found in the [LICENSE](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjferrl%2Fgo-event","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjferrl%2Fgo-event","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjferrl%2Fgo-event/lists"}