client/events.go
func (e *EventListener) AddHandler(types []string, function func(api.Event)) (*EventTarget, error) {
	if function == nil {
		return nil, fmt.Errorf("A valid function must be provided")
	}

	// Handle locking
	e.targetsLock.Lock()
	defer e.targetsLock.Unlock()

	// Create a new target
	target := EventTarget{
		function: function,
		types:    types,
	}

	// And add it to the targets
	e.targets = append(e.targets, &target)

	return &target, nil
}
func (e *EventListener) AddHandler(types []string, function func(api.Event)) (*EventTarget, error) {
	if function == nil {
		return nil, fmt.Errorf("A valid function must be provided")
	}

	// Handle locking
	e.targetsLock.Lock()
	defer e.targetsLock.Unlock()

	// Create a new target
	target := EventTarget{
		function: function,
		types:    types,
	}

	// And add it to the targets
	e.targets = append(e.targets, &target)

	return &target, nil
}
func ( e * EventListener ) AddHandler ( types [ ] string , function func ( api . Event ) ) ( * EventTarget , error ) { if function == nil { return nil , fmt . Errorf ( " " ) } // Handle locking e . targetsLock . Lock ( ) defer e . targetsLock . Unlock ( ) // Create a new target target := EventTarget { function : function , types : types , } // And add it to the targets e . targets = append ( e . targets , & target ) return & target , nil }
// AddHandler adds a function to be called whenever an event is received
AddHandler adds a function to be called whenever an event is received