{"id":13413393,"url":"https://github.com/agoalofalife/event","last_synced_at":"2025-03-22T18:33:55.684Z","repository":{"id":57489176,"uuid":"96021474","full_name":"agoalofalife/event","owner":"agoalofalife","description":"The implementation of the pattern observer","archived":false,"fork":false,"pushed_at":"2018-02-19T12:11:32.000Z","size":32,"stargazers_count":58,"open_issues_count":0,"forks_count":13,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-18T13:51:30.196Z","etag":null,"topics":["event","event-go","events","go","go-event","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/agoalofalife.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}},"created_at":"2017-07-02T12:19:56.000Z","updated_at":"2024-08-20T15:27:20.000Z","dependencies_parsed_at":"2022-08-29T22:11:47.609Z","dependency_job_id":null,"html_url":"https://github.com/agoalofalife/event","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agoalofalife%2Fevent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agoalofalife%2Fevent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agoalofalife%2Fevent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agoalofalife%2Fevent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/agoalofalife","download_url":"https://codeload.github.com/agoalofalife/event/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245003465,"owners_count":20545615,"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":["event","event-go","events","go","go-event","golang"],"created_at":"2024-07-30T20:01:39.306Z","updated_at":"2025-03-22T18:33:55.404Z","avatar_url":"https://github.com/agoalofalife.png","language":"Go","funding_links":[],"categories":["Messaging","消息","消息系统","Relational Databases","消息传递","\u003cspan id=\"消息-messaging\"\u003e消息 Messaging\u003c/span\u003e","机器学习"],"sub_categories":["Search and Analytic Databases","Advanced Console UIs","检索及分析资料库","SQL 查询语句构建库","交流","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"readme":"\n\n## Event\n[![Build Status](https://travis-ci.org/agoalofalife/event.svg?branch=master)](https://travis-ci.org/agoalofalife/event)\n[![codecov](https://codecov.io/gh/agoalofalife/event/branch/master/graph/badge.svg)](https://codecov.io/gh/agoalofalife/event)\n[![Go Report Card](https://goreportcard.com/badge/github.com/agoalofalife/event)](https://goreportcard.com/report/github.com/agoalofalife/event)\n[![GoDoc](http://godoc.org/github.com/agoalofalife/event?status.svg)](http://godoc.org/github.com/agoalofalife/event)\n\nThis is package implements [pattern-observer](https://en.wikipedia.org/wiki/Observer_pattern)\n\n### Fast example\n\n```go\nimport (\n\t\"github.com/agoalofalife/event\"\n)\n\nfunc main() {\n\t// create struct\n\te := event.New()\n\n\t// subscriber \n\te.Add(\"push.email\", func(text string){\n    \t// some logic \n    }, \"text\")\n    \n    // init event\n    e.Fire(\"push.email\") // or e.Go(\"push.email\")\n}\n```\n\nlet us consider an example:\n\n * You must first create the structure\n * Next, the first argument declares the name of the event (string type), second argument  executes when the event occurs, the third argument is passed a list of arguments, which are substituted in the parameters of the second argument.\n * In the end you need to run the event. There are two methods available \"Go\" and his alias \"Fire\"\n\n### The subscriber function method\n\n```go\ntype Email struct {\n\tcount int\n}\nfunc (e *Email) Push() {\n\te.count += 1\n\tfmt.Printf(\"Push email again, count %d \\n\", e.count)\n}\nfunc main() {\n\te := event.New()\n\t\n\temail := new(Email)\n\t\n\te.Add(email, email.Push)\n\te.Fire(email)\n\te.Fire(email)\n}\n// output \n// Push email again, count 1 \n// Push email again, count 2 \n```\n\n## Bench\n```\n// create struct and add new event handler\nBenchmarkAdd-8           1000000              1482 ns/op\n\n// create struct and add new event handler and N run this handler\nBenchmarkGo-8            5000000               339 ns/op\n\n```\n* In this example we sign the event method structure\n\n \nRead more information in [examples](https://github.com/agoalofalife/event/tree/master/examples) :+1:\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagoalofalife%2Fevent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagoalofalife%2Fevent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagoalofalife%2Fevent/lists"}