event

package
v0.0.0-...-aec1c34 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilNATSConnObj   = errors.New("nil nats conn obj received")
	ErrInvalidPayload   = errors.New("invalid payload")
	ErrUnsupportedEvent = errors.New("unsupported event")
)

Errors of event package

View Source
var Registry = &EventRegistry{
	Registry: make(map[EventName]EventInfo),
}

Registry is the service EventRegistry where all the active events which are to be fired or handled must register themselves

Functions

This section is empty.

Types

type ErrEventReqChNotSet

type ErrEventReqChNotSet struct {
	Name EventName
}

func (*ErrEventReqChNotSet) Error

func (e *ErrEventReqChNotSet) Error() string

type ErrNewEvent

type ErrNewEvent struct {
	Name EventName
}

func (*ErrNewEvent) Error

func (e *ErrNewEvent) Error() string

type ErrNilVerifyFunc

type ErrNilVerifyFunc struct {
	Name EventName
}

func (*ErrNilVerifyFunc) Error

func (e *ErrNilVerifyFunc) Error() string

type ErrUnregisteredEvent

type ErrUnregisteredEvent struct {
	Name EventName
}

func (*ErrUnregisteredEvent) Error

func (e *ErrUnregisteredEvent) Error() string

type Event

type Event struct {
	Meta    EventMeta   `json:"meta"`
	Payload interface{} `json:"payload"`
}

func (*Event) GetPayload

func (e *Event) GetPayload() interface{}

func (*Event) Name

func (e *Event) Name() string

func (*Event) Publish

func (e *Event) Publish(nc *nats.EncodedConn) error

type EventAccountAuthenticatedPayload

type EventAccountAuthenticatedPayload struct {
	AccntID uint `json:"accnt_id"`
}

type EventAccountCreatedPayload

type EventAccountCreatedPayload struct {
	AccntID uint   `json:"accnt_id"`
	Role    string `json:"role"`
}

type EventAccountDeletedPayload

type EventAccountDeletedPayload struct {
	AccntID uint `json:"accnt_id"`
}

type EventInfo

type EventInfo struct {
	ReqChan  string
	RespChan string
	// contains filtered or unexported fields
}

type EventMeta

type EventMeta struct {
	Version   string    `json:"version"`
	Source    string    `json:"source"`
	Time      time.Time `json:"time"`
	Name      string    `json:"name"`
	ID        string    `json:"id"`
	RequestID string    `json:"req_id"`
}

type EventName

type EventName string
const EventAccountAuthenticated EventName = "EventAccountAuthenticated"
const EventAccountCreated EventName = "EventAccountCreated"
const EventAccountDeleted EventName = "EventAccountDeleted"
const EventPolicyUpdated EventName = "EventPolicyUpdated"
const EventUpsertPolicy EventName = "EventUpsertPolicy"

type EventPolicyUpdatedPayload

type EventPolicyUpdatedPayload struct {
	Method       string `json:"method"` // could be put/delete
	Sub          string `json:"subject"`
	ResourceType string `json:"resource_type"`
	ResourceID   string `json:"resource_id"`
	Action       string `json:"action"`
}

type EventPublisher

type EventPublisher struct {
	// contains filtered or unexported fields
}

EventPublisher makes it easy to add events and send them all at once

func NewEventPublisher

func NewEventPublisher() *EventPublisher

func (*EventPublisher) AddEvent

func (ep *EventPublisher) AddEvent(e IEvent, err error) error

func (*EventPublisher) GetEventNames

func (ep *EventPublisher) GetEventNames() (names []string)

func (*EventPublisher) Publish

func (ep *EventPublisher) Publish(nc *nats.EncodedConn) error

Publish publishes the added events to registered NATS subjects if error occurs while publishing any event, the publisher returns the error immediately instead of try publishing other events

type EventRegistry

type EventRegistry struct {
	Registry map[EventName]EventInfo
}

Registry holds all the event name and their transport details mapping It helps in verifying the event name and getting their request/response channel

func (*EventRegistry) GetEventInfo

func (er *EventRegistry) GetEventInfo(name EventName) (EventInfo, error)

type EventUpsertPolicyPayload

type EventUpsertPolicyPayload struct {
	Sub          string `json:"subject"`
	ResourceType string `json:"resource_type"`
	ResourceID   string `json:"resource_id"`
	Action       string `json:"action"`
}

type IEvent

type IEvent interface {
	Name() string
	GetPayload() interface{}
	Publish(*nats.EncodedConn) error
}

func NewEvent

func NewEvent(ctx context.Context, name EventName, payload interface{}) (IEvent, error)

NewEvent is the factory to generate all the event

Jump to

Keyboard shortcuts

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