event

package
v0.0.0-...-eecab09 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNewEventTypeMapper = errors.New("unknown event")
)

Functions

func GetTypeName

func GetTypeName(source interface{}) (reflect.Type, string)

GetTypeName of given struct.

Types

type Consumer

type Consumer interface {
	SubscribeEvent(ctx context.Context, topic string, handler MessageHandlerFunc) error
	Close() error
}

type DomainEvent

type DomainEvent struct {
	ID        uuid.UUID   // 事件唯一ID
	EventType string      // 事件的Type名稱,例如:AccountCreatedEvent
	Data      interface{} // 事件資料,例如&AccountCreatedEvent{}
	CreatedAt time.Time

	AggregateType string // 事件所屬的Aggregate Type,例如AccountCreatedEvent屬於Account
	AggregateID   string // aggregate儲存在資料庫,相對應的ID
	Version       int    // aggregate的版本
}

func NewDomainEvent

func NewDomainEvent(aggregateID, aggregateType string, version int, data interface{}) *DomainEvent

func (*DomainEvent) GetAggregateID

func (e *DomainEvent) GetAggregateID() string

AggregateID implements the AggregateID method of the Event interface.

func (*DomainEvent) GetAggregateType

func (e *DomainEvent) GetAggregateType() string

AggregateType implements the AggregateType method of the Event interface.

func (*DomainEvent) GetData

func (e *DomainEvent) GetData() interface{}

Data implements the Data method of the Event interface.

func (*DomainEvent) GetEventType

func (e *DomainEvent) GetEventType() string

EventType implements the EventType method of the Event interface.

func (*DomainEvent) GetID

func (e *DomainEvent) GetID() uuid.UUID

func (*DomainEvent) GetVersion

func (e *DomainEvent) GetVersion() int

Version implements the Version method of the Event interface.

func (*DomainEvent) SetEventType

func (e *DomainEvent) SetEventType(et string)

func (*DomainEvent) SetTimestamp

func (e *DomainEvent) SetTimestamp() time.Time

Timestamp implements the Timestamp method of the Event interface.

func (*DomainEvent) SetVersion

func (e *DomainEvent) SetVersion(v int)

type Event

type Event interface {
	GetEventType() string
	GetData() interface{}
	CreatedAt() time.Time

	GetAggregateType() string
	GetAggregateID() string
	GetVersion() int

	Serialize() (string, error)
	Deserialize(string) (interface{}, error)
}

type MessageHandlerFunc

type MessageHandlerFunc func(key string, message string) error

type Producer

type Producer interface {
	// PublishEvent publish event to pubsub server.
	PublishEvent(ctx context.Context, topic string, event interface{}) error

	// Close connection.
	Close() error
}

type RoleCreatedEvent

type RoleCreatedEvent struct {
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Permissions []string `json:"permissions"`
}

type RoleDescriptionChangedEvent

type RoleDescriptionChangedEvent struct {
	Description string `json:"description"`
}

type RolePermissionUpdatedEvent

type RolePermissionUpdatedEvent struct {
	Permissions []string `json:"permissions"`
}

type Store

type Store interface {
	Store(ctx context.Context, events []DomainEvent, version int) error
	Load(ctx context.Context, aggregateID string, version int) ([]DomainEvent, error)
	SafeStore(ctx context.Context, events []DomainEvent, expectedVersion int) error
}

type TypeMapper

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

func NewEventTypeMapper

func NewEventTypeMapper() *TypeMapper

func (*TypeMapper) NewInstance

func (m *TypeMapper) NewInstance(eventName string) (event interface{}, err error)

func (*TypeMapper) Register

func (m *TypeMapper) Register(event interface{})

type UserCreatedEvent

type UserCreatedEvent struct {
	UserName string `json:"user_name"`
	Password string `json:"password"`
	EMail    string `json:"email"`
}

type UserEmailChangedEvent

type UserEmailChangedEvent struct {
	EMail string `json:"email"`
}

type UserPasswordChangedEvent

type UserPasswordChangedEvent struct {
	Password string `json:"password"`
}

Jump to

Keyboard shortcuts

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