{"id":19900627,"url":"https://github.com/gobuffalo/events","last_synced_at":"2026-03-12T09:44:09.709Z","repository":{"id":34638569,"uuid":"149316514","full_name":"gobuffalo/events","owner":"gobuffalo","description":"Buffalo framework events management","archived":false,"fork":false,"pushed_at":"2022-09-26T04:37:23.000Z","size":91,"stargazers_count":16,"open_issues_count":0,"forks_count":3,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-07T08:18:18.728Z","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/gobuffalo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"markbates","patreon":"buffalo"}},"created_at":"2018-09-18T16:07:34.000Z","updated_at":"2024-06-26T04:17:26.000Z","dependencies_parsed_at":"2023-01-15T08:14:12.751Z","dependency_job_id":null,"html_url":"https://github.com/gobuffalo/events","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gobuffalo%2Fevents","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gobuffalo%2Fevents/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gobuffalo%2Fevents/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gobuffalo%2Fevents/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gobuffalo","download_url":"https://codeload.github.com/gobuffalo/events/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252122211,"owners_count":21698305,"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":["events","go","golang"],"created_at":"2024-11-12T20:12:48.353Z","updated_at":"2026-03-12T09:44:09.656Z","avatar_url":"https://github.com/gobuffalo.png","language":"Go","funding_links":["https://github.com/sponsors/markbates","https://patreon.com/buffalo"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"https://github.com/gobuffalo/buffalo/blob/master/logo.svg\" width=\"360\"\u003e\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://godoc.org/github.com/gobuffalo/events\"\u003e\u003cimg src=\"https://godoc.org/github.com/gobuffalo/events?status.svg\" alt=\"GoDoc\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/gobuffalo/events/actions\"\u003e\u003cimg src=\"https://github.com/gobuffalo/events/actions/workflows/tests.yml/badge.svg\" alt=\"Build status\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://goreportcard.com/report/github.com/gobuffalo/events\"\u003e\u003cimg src=\"https://goreportcard.com/badge/github.com/gobuffalo/events\" alt=\"Go Report Card\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n# github.com/gobuffalo/events\n\n**Note:** This package was first introduced to Buffalo in this [PR](https://github.com/gobuffalo/buffalo/pull/1305). Assuming the PR is merged Buffalo will not start emitting events until `v0.13.0-beta.2` or greater.\n\nA list of known emitted events can be found at [https://godoc.org/github.com/gobuffalo/events#pkg-constants](https://godoc.org/github.com/gobuffalo/events#pkg-constants)\n\n## Installation\n\n```bash\n$ go get -u -v github.com/gobuffalo/events\n```\n\n## Listening For Events\n\nTo listen for events you need to register an [`events#Listener`](https://godoc.org/github.com/gobuffalo/events#Listener) function first.\n\n```go\nfunc init() {\n  // if you want to give your listener a nice name to identify itself\n  events.NamedListen(\"my-listener\", func(e events.Event) {\n    fmt.Println(\"### e -\u003e\", e)\n  })\n\n  // if you don't care about identifying your listener\n  events.Listen(func(e events.Event) {\n    fmt.Println(\"### e -\u003e\", e)\n  })\n}\n```\n\n## Emitting Events\n\n```go\nevents.Emit(events.Event{\n  Kind:    \"my-event\",\n  Message: // optional message,\n  Payload: // optional payload,\n  Error:   // optional error,\n})\n```\n\nThere is only one required field when emitting an event, `Kind`.\n\nThe `Kind` field is key to how people will interpret your messages, and should be constructed as such: `\u003cnamespace\u003e:\u003cevent-kind\u003e:\u003cerr-optional\u003e`.\n\nIn the examples below from [Buffalo](https://gobuffalo.io) you can see it is using the `buffalo:` name space for its events.\n\n```go\n// EvtAppStart is emitted when buffalo.App#Serve is called\nEvtAppStart = \"buffalo:app:start\"\n// EvtAppStartErr is emitted when an error occurs calling buffalo.App#Serve\nEvtAppStartErr = \"buffalo:app:start:err\"\n// EvtAppStop is emitted when buffalo.App#Stop is called\nEvtAppStop = \"buffalo:app:stop\"\n// EvtAppStopErr is emitted when an error occurs calling buffalo.App#Stop\nEvtAppStopErr = \"buffalo:app:stop:err\"\n```\n\n## Implementing a Manager\n\nBy default `events` implements a basic manager for you. Should you want to replace that with your own implementation, perhaps that's backed by a proper message queue, you can implement the [`events#Manager`](https://godoc.org/github.com/gobuffalo/events#Manager) interface.\n\n```go\nvar _ events.Manager = MyManager{}\nevents.SetManager(MyManager{})\n```\n\n## Listening via Buffalo Plugins\n\nOnce Buffalo is actively emitting events, plugins, will be able to listen those events via their CLIs.\n\nTo do so you can set the `BuffaloCommand` to `events` when telling Buffalo which plugin in commands are available. Buffalo will create a new listener that says the JSON version of the event to that command in question.\n\n```go\nvar availableCmd = \u0026cobra.Command{\n\tUse:   \"available\",\n\tShort: \"a list of available buffalo plugins\",\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tplugs := plugins.Commands{\n\t\t\t{Name: \"echo\", UseCommand: \"echo\", BuffaloCommand: \"events\", Description: echoCmd.Short, Aliases: echoCmd.Aliases},\n\t\t}\n\t\treturn json.NewEncoder(os.Stdout).Encode(plugs)\n\t},\n}\n\n\nevents.Emit(events.Event{\n  Kind:    \"my-event\",\n})\n\n// buffalo-foo echo \"{\\\"kind\\\": \\\"my-event\\\"}\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgobuffalo%2Fevents","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgobuffalo%2Fevents","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgobuffalo%2Fevents/lists"}