hook

package
v0.0.0-...-50592dc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Define events
	Created Event = "created"
	Updated Event = "updated"
	Deleted Event = "deleted"

	// Define scopes
	UserScope Scope = "user"

	// Event source
	SourceUserAPI = "user_api"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event string

type EventPayload

type EventPayload struct {
	Name       Event
	Scope      Scope
	Source     string
	PayloadOld interface{}
	Payload    interface{}
}

type Hooker

type Hooker struct {
	Subscribers       []Subscriber
	ScopedSubscribers map[Scope][]Subscriber
}

func CreateHooker

func CreateHooker() *Hooker

func (*Hooker) AddScopedSubscriber

func (h *Hooker) AddScopedSubscriber(scope Scope, subscriber Subscriber)

func (*Hooker) AddSubscriber

func (h *Hooker) AddSubscriber(subscriber Subscriber)

func (*Hooker) Trigger

func (h *Hooker) Trigger(payload EventPayload)

func (*Hooker) TriggerScopedSubscriber

func (h *Hooker) TriggerScopedSubscriber(payload EventPayload)

type HookerInterface

type HookerInterface interface {
	Trigger(event Event, payload interface{})
	AddSubscriber(scope Scope, subscriber Subscriber)
}

type RawEventPayload

type RawEventPayload struct {
	Name    Event  `json:"name"`
	Scope   Scope  `json:"scope"`
	Source  string `json:"source"`
	Payload []byte `json:"payload"`
}

type Scope

type Scope string

type Subscriber

type Subscriber interface {
	Created(payload EventPayload)
	Updated(payload EventPayload)
	Deleted(payload EventPayload)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL