• Stars
    star
    95
  • Rank 341,593 (Top 7 %)
  • Language
    Go
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ“£ Pure nodejs EventEmmiter for the Go Programming Language.


build status chat donate

Simple EventEmmiter for Go Programming Language. Inspired by Nodejs EventEmitter. For Generics support please wait until go1.18 stable is released, until then switch to dev branch instead.

Overview

New() EventEmmiter // New returns a new, empty, EventEmmiter

// AddListener is an alias for .On(eventName, listener).
AddListener(EventName, ...Listener)
// Emit fires a particular event,
// Synchronously calls each of the listeners registered for the event named
// eventName, in the order they were registered,
// passing the supplied arguments to each.
Emit(EventName, ...interface{})
// EventNames returns an array listing the events for which the emitter has registered listeners.
// The values in the array will be strings.
EventNames() []EventName
// GetMaxListeners returns the max listeners for this emmiter
// see SetMaxListeners
GetMaxListeners() int
// ListenerCount returns the length of all registered listeners to a particular event
ListenerCount(EventName) int
// Listeners returns a copy of the array of listeners for the event named eventName.
Listeners(EventName) []Listener
// On registers a particular listener for an event, func receiver parameter(s) is/are optional
On(EventName, ...Listener)
// Once adds a one time listener function for the event named eventName.
// The next time eventName is triggered, this listener is removed and then invoked.
Once(EventName, ...Listener)
// RemoveAllListeners removes all listeners, or those of the specified eventName.
// Note that it will remove the event itself.
// Returns an indicator if event and listeners were found before the remove.
RemoveAllListeners(EventName) bool
// Clear removes all events and all listeners, restores Events to an empty value
Clear()
// SetMaxListeners obviously this function allows the MaxListeners
// to be decrease or increase. Set to zero for unlimited
SetMaxListeners(int)
// Len returns the length of all registered events
Len() int
import "github.com/kataras/go-events"

// initialize a new EventEmmiter to use
e := events.New()

// register an event with name "my_event" and one listener
e.On("my_event", func(payload ...interface{}) {
  message := payload[0].(string)
  print(message) // prints "this is my payload"
})

// fire the 'my_event' event
e.Emit("my_event", "this is my payload")

Default/global EventEmmiter

// register an event with name "my_event" and one listener to the global(package level) default EventEmmiter
events.On("my_event", func(payload ...interface{}) {
  message := payload[0].(string)
  print(message) // prints "this is my payload"
})

// fire the 'my_event' event
events.Emit("my_event", "this is my payload")

Remove an event

events.On("my_event", func(payload ...interface{}) {
  // first listener...
},func (payload ...interface{}){
  // second listener...
})

println(events.Len()) // prints 1
println(events.ListenerCount("my_event")) // prints 2

// Remove our event, when/if we don't need this or we want to clear all of its listeners
events.RemoveAllListeners("my_event")

println(events.Len()) // prints 0
println(events.ListenerCount("my_event")) // prints 0

Installation

The only requirement is the Go Programming Language.

$ go get -u github.com/kataras/go-events

FAQ

Explore these questions or navigate to the [community chat][Chat].

Versioning

Current: v0.0.3

Read more about Semantic Versioning 2.0.0

Contributing

If you are interested in contributing to the go-events project, please prepare a PR.

License

This project is licensed under the MIT License.

License can be found here.

More Repositories

1

iris

The fastest HTTP/2 Go Web Framework. New, modern and easy to learn. Fast development with Code you control. Unbeatable cost-performance ratio πŸš€
Go
24,712
star
2

neffos

A modern, fast and scalable websocket framework with elegant API written in Go
Go
559
star
3

golog

A high-performant Logging Foundation for Go Applications. X3 faster than the rest leveled loggers.
Go
317
star
4

muxie

Muxie is a modern, fast and light HTTP multiplexer for Go. Fully compatible with the http.Handler interface. Written for everyone.
Go
282
star
5

go-sessions

πŸ” The sessions manager for the Go Programming Language. Supports both net/http and fasthttp.
Go
204
star
6

rizla

πŸ‘€ Rizla builds, runs and monitors your Go Applications with ease. See https://github.com/kataras/iris-cli for Iris users.
Go
190
star
7

jwt

A fast and simple JWT implementation for Go
Go
189
star
8

iris-cli

[WIP] Iris Command Line Interface
Go
117
star
9

i18n

πŸ†• High-performant and powerful localization and internationalization support for Go
Go
103
star
10

server-benchmarks

πŸš€ Cross-platform transparent benchmarks for HTTP/2 Web Servers at 2020-2023
Go
85
star
11

blocks

Go-idiomatic View Engine
Go
69
star
12

go-websocket

πŸ”ˆ Deprecated. Use https://github.com/kataras/neffos instead
Go
59
star
13

go-template

πŸ”ˆ Deprecated. Use https://github.com/kataras/iris/wiki/View instead
Go
56
star
14

versioning

πŸ†• API Versioning for Go
Go
50
star
15

build-a-better-web-together

Deprecated. Moved to https://github.com/kataras/iris/wiki and https://docs.iris-go.com
CSS
48
star
16

httpcache

ABANDONED: Use https://github.com/kataras/iris instead. Extremely-easy cache service for HTTP/x . Supports both net/http and valyala/fasthttp
Go
43
star
17

neffos.js

Node.js and Browser support for the neffos real-time framework written in Typescript.
TypeScript
39
star
18

hcaptcha

hCaptcha HTTP middleware for Go web servers
Go
32
star
19

pg

PG is a Go library that simplifies PostgreSQL database interaction with struct-based entities, schema management, and repository pattern.
Go
27
star
20

tunnel

Public URLs for exposing your local web server
Go
26
star
21

go-fs

πŸ“ Provides some common utilities which GoLang developers use when working with files, either system files or web files.
Go
26
star
22

rewrite

The rewrite middleware for Go. Perfect for SEO
Go
22
star
23

pio

Low-level package that provides an easy way to centralize different output targets. Supports colors and text decoration to all popular terminals
Go
20
star
24

httpfs

Flexible and easy to use HTTP File Server for Go
Go
19
star
25

sitemap

πŸ†• Sitemap Protocol for Go | https://support.google.com/webmasters/answer/189077?hl=en
Go
19
star
26

go-errors

⚠️ Better GoLang error handling.
Go
18
star
27

compress

HTTP Compression for Go
Go
16
star
28

go-serializer

➿ Serialize any custom type or convert any content to []byte or string, for Go Programming Language
Go
16
star
29

chronos

NEW: Chronos provides an easy way to limit X operations per Y time in accuracy of nanoseconds
Go
14
star
30

basicauth

The most advanced and powerful Go HTTP Basic Authentication middleware.
Go
13
star
31

gitbook-to-wiki

Export your GitBook as a GitHub Wiki or Docsify pages.
Go
13
star
32

sheets

πŸ“Š (Unofficial) A Lightweight Google Spreadsheets Client written in Go
Go
12
star
33

vscode-iris

Iris Web Framework snippets for Visual Studio Code
TypeScript
9
star
34

realip

Extract the real HTTP client's Remote IP Address
Go
8
star
35

methodoverride

πŸ†• Lets you use HTTP verbs such as PUT or DELETE in places where the client doesn't support it
Go
7
star
36

trie-examples-to-remember-again

A place to keep my coding examples for different kind of trie usage in order to remember them again - this time on github
Go
7
star
37

requestid

Unique Identifier for each HTTP request
Go
6
star
38

go-options

πŸ“¦ Clean APIs for your Go Applications
Go
5
star
39

httpclient

HTTP/2 Client for Go Programming Language #golang #http
Go
4
star
40

mail

Mail is a ridiculous simple email sender written in Go
Go
4
star
41

pkg

Public Repository of the common packages that Gerasimos Maropoulos, the author of Iris, uses for various commercial or non-commercial projects.
Go
4
star
42

pgx-golog

pgx and golog integration
Go
3
star
43

kataras

Gerasimos Maropoulos
1
star