Import event handling
This commit is contained in:
parent
5511955438
commit
37bb460561
26
event/msg.go
26
event/msg.go
@ -2,6 +2,7 @@ package event
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -37,3 +38,28 @@ type EventTokenMint struct {
|
|||||||
TxHash string
|
TxHash string
|
||||||
VoucherAddress string
|
VoucherAddress string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type EventsHandlerFunc func(context.Context, any) error
|
||||||
|
|
||||||
|
type EventsHandler struct {
|
||||||
|
handlers map[string]EventsHandlerFunc
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEventsHandler() *EventsHandler {
|
||||||
|
return &EventsHandler{
|
||||||
|
handlers: make(map[string]EventsHandlerFunc),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (eh *EventsHandler) WithHandler(tag string, fn EventsHandlerFunc) *EventsHandler {
|
||||||
|
eh.handlers[tag] = fn
|
||||||
|
return eh
|
||||||
|
}
|
||||||
|
|
||||||
|
func (eh *EventsHandler) Handle(ctx context.Context, tag string, o any) error {
|
||||||
|
fn, ok := eh.handlers[tag]
|
||||||
|
if !ok {
|
||||||
|
fmt.Errorf("Handler not registered for tag: %s", tag)
|
||||||
|
}
|
||||||
|
return fn(ctx, o)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user