events

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func MakeHTTPHandler

func MakeHTTPHandler(b *EventBroadcaster) http.Handler

MakeHTTPHandler returns a handler that makes a set of endpoints available on predefined paths.

Types

type Emitter

type Emitter interface {
	// Emit fires an event with the given name and payload.
	Emit(EventName, interface{})
	// On registers a listener for the given event name.
	On(EventName, ...Listener)
	// OnMany registers a listener for the given event names.
	ListenEvents(Listener, ...EventName)
}

Emitter is an interface that allows to fire events.

func NewEmitter

func NewEmitter(log Logger) Emitter

NewEmitter creates a new Emitter.

type Event

type Event struct {
	Channel string      `json:"-"`
	Name    string      `json:"name"`
	Data    interface{} `json:"data"`
}

type EventBroadcaster

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

func NewEventBroadcaster

func NewEventBroadcaster(emitter Emitter, log Logger) *EventBroadcaster

func (*EventBroadcaster) RetranslateEvents

func (b *EventBroadcaster) RetranslateEvents(event EventName, payload interface{}) error

RetranslateEvents retranslates events from the emitter to the event Broadcaster.

func (*EventBroadcaster) Run

func (b *EventBroadcaster) Run(ctx context.Context) error

Run starts the event Broadcaster.

type EventName

type EventName string

EventName is a string alias for event names.

const (
	PaymentCreated                   EventName = "payment.created"
	PaymentProcessing                EventName = "payment.processing"
	PaymentCancelled                 EventName = "payment.cancelled"
	PaymentFailed                    EventName = "payment.failed"
	PaymentExpired                   EventName = "payment.expired"
	PaymentSucceeded                 EventName = "payment.succeeded"
	PaymentLinkGenerated             EventName = "payment.link.generated"
	TransactionCreated               EventName = "transaction.created"
	TransactionUpdated               EventName = "transaction.updated"
	TransactionReferenceNotification EventName = "transaction.reference.notification"
)

Predefined

type Listener

type Listener func(EventName, interface{}) error

Listener is a function that is called when an event is fired.

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Errorf(format string, args ...interface{})
}

Logger is an interface that allows to log events.

type PaymentCreatedPayload

type PaymentCreatedPayload struct {
	PaymentID
}

Event payloads.

type PaymentID

type PaymentID struct {
	PaymentID string `json:"payment_id"`
}

PaymentIDGetter struct for getting payment_id from event payload.

func (PaymentID) GetPaymentID

func (p PaymentID) GetPaymentID() string

GetPaymentID returns payment_id from event payload. This method is required for PaymentIDGetter interface.

type PaymentIDGetter

type PaymentIDGetter interface {
	GetPaymentID() string
}

PaymentID is an interface for all events that have payment_id field.

type PaymentLinkGeneratedPayload

type PaymentLinkGeneratedPayload struct {
	PaymentID
	Link string `json:"link"`
}

Event payloads.

type PaymentStatusUpdatedPayload

type PaymentStatusUpdatedPayload struct {
	PaymentID
	Status string `json:"status"`
}

Event payloads.

type ReferencePayload

type ReferencePayload struct {
	Reference string `json:"reference"`
}

Event payloads.

type TransactionCreatedPayload

type TransactionCreatedPayload struct {
	PaymentID
	TransactionID string `json:"transaction_id"`
	Reference     string `json:"reference"`
}

Event payloads.

type TransactionUpdatedPayload

type TransactionUpdatedPayload struct {
	PaymentID
	Reference   string      `json:"reference"`
	Status      string      `json:"status"`
	Signature   string      `json:"signature"`
	Transaction interface{} `json:"transaction,omitempty"`
}

Event payloads.

Jump to

Keyboard shortcuts

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