Documentation ¶
Index ¶
- Constants
- type BaseEvent
- type CartClearedEvent
- type CartEvent
- type CartEventType
- type CartItem
- type CartPaymentSuccessEvent
- type CartSelectionEvent
- type CartUpdatedEvent
- type CouponEvent
- type DeliveryMode
- type Event
- type EventError
- type EventHandler
- type EventProcessor
- type EventType
- type EventValidator
- type InventoryEvent
- type InventoryEventType
- type InventoryPaymentFailedEvent
- type InventoryPaymentSuccessEvent
- type MarketingEvent
- type MarketingEventType
- type MarketingPaymentFailedEvent
- type MarketingPaymentSuccessEvent
- type MessageBatchEvent
- type MessageEvent
- type MessageEventSentEvent
- type MessageEventType
- type MessagePaymentFailedEvent
- type MessagePaymentSuccessEvent
- type MessageTemplate
- type MessageTemplateEvent
- type Metadata
- type MetadataBuilder
- type NonRetryableError
- type OrderAlertEvent
- type OrderCancelledEvent
- type OrderCompletedEvent
- type OrderCreatedEvent
- type OrderEvent
- type OrderEventType
- type OrderItem
- type OrderPaidEvent
- type OrderPaymentFailedEvent
- type OrderPaymentRefundedEvent
- type OrderPaymentSuccessEvent
- type OrderRefundedEvent
- type OrderShippedEvent
- type OrderStatusChangedEvent
- type OrderStatusEventType
- type PaymentCreatedEvent
- type PaymentEvent
- type PaymentEventType
- type PaymentFailedEvent
- type PaymentRefundEvent
- type PaymentSuccessEvent
- type PaymentVerificationEvent
- type PointsEvent
- type PromotionEvent
- type RetryableError
- type StockAlertEvent
- type StockCheckedEvent
- type StockDeductedEvent
- type StockItem
- type StockLockedEvent
- type StockLowStockEvent
- type StockOutOfStockEvent
- type StockReservedEvent
- type StockUnlockedEvent
- type StockUpdatedEvent
Constants ¶
const ( DirectExchange = "direct" FanoutExchange = "fanout" TopicExchange = "topic" HeadersExchange = "headers" )
Exchange types
const ( EventStatusPending = "pending" EventStatusSuccess = "success" EventStatusFailed = "failed" EventStatusRetrying = "retrying" )
Common event status
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseEvent ¶
type BaseEvent struct {
Metadata *Metadata `json:"metadata"`
}
BaseEvent provides common functionality for all events
func (*BaseEvent) GetMetadata ¶
GetMetadata returns event metadata
func (*BaseEvent) WithMetadata ¶
WithMetadata adds metadata to an event
type CartClearedEvent ¶
CartClearedEvent represents cart clearing event
type CartEvent ¶
type CartEvent struct { Type CartEventType `json:"type"` UserID int64 `json:"user_id"` Timestamp time.Time `json:"timestamp"` }
CartEvent represents the base cart event structure
type CartEventType ¶
type CartEventType string
const ( CartUpdated CartEventType = "cart.updated" CartCleared CartEventType = "cart.cleared" CartSelected CartEventType = "cart.selected" CartUnselected CartEventType = "cart.unselected" CartPaymentSuccess CartEventType = "cart.payment.success" )
type CartItem ¶
type CartItem struct { ProductID int64 `json:"product_id"` SkuID int64 `json:"sku_id"` Quantity int32 `json:"quantity"` Selected bool `json:"selected"` Price float64 `json:"price"` }
CartItem represents an item in the cart
type CartPaymentSuccessEvent ¶
type CartPaymentSuccessEvent struct { CartEvent OrderNo string `json:"order_no"` PaymentNo string `json:"payment_no"` ClearTime time.Time `json:"clear_time"` Items []CartItem `json:"items"` }
CartPaymentSuccessEvent represents cart clearing after successful payment
func (*CartPaymentSuccessEvent) Validate ¶
func (e *CartPaymentSuccessEvent) Validate() error
Add validation method
type CartSelectionEvent ¶
CartSelectionEvent represents item selection status change
type CartUpdatedEvent ¶
CartUpdatedEvent represents cart update event
type CouponEvent ¶
type CouponEvent struct { MarketingEvent CouponID int64 `json:"coupon_id"` CouponCode string `json:"coupon_code"` Amount float64 `json:"amount"` OrderNo string `json:"order_no,omitempty"` }
CouponEvent represents coupon-related events
type DeliveryMode ¶
type DeliveryMode int
DeliveryMode defines message delivery guarantees
const ( // NonPersistent messages may be lost NonPersistent DeliveryMode = 1 // Persistent messages are written to disk Persistent DeliveryMode = 2 )
type Event ¶
type Event struct { Type EventType `json:"type"` Data interface{} `json:"data"` Metadata *Metadata `json:"metadata"` }
Event represents the base event structure
type EventError ¶
EventError represents a base error type for event processing
func (*EventError) Error ¶
func (e *EventError) Error() string
type EventHandler ¶
EventHandler represents a function that handles an event
type EventProcessor ¶
EventProcessor defines the interface for processing events
type EventValidator ¶
type EventValidator interface {
Validate() error
}
EventValidator defines the interface for validating events
type InventoryEvent ¶
type InventoryEvent struct { Type InventoryEventType `json:"type"` WarehouseID int64 `json:"warehouse_id"` Timestamp time.Time `json:"timestamp"` }
InventoryEvent represents the base inventory event structure
type InventoryEventType ¶
type InventoryEventType string
const ( StockLocked InventoryEventType = "inventory.stock.locked" StockUnlocked InventoryEventType = "inventory.stock.unlocked" StockDeducted InventoryEventType = "inventory.stock.deducted" StockIncremented InventoryEventType = "inventory.stock.incremented" StockAlert InventoryEventType = "inventory.stock.alert" StockChecked InventoryEventType = "inventory.stock.checked" StockReserved InventoryEventType = "inventory.stock.reserved" StockUpdated InventoryEventType = "inventory.stock.updated" StockOutOfStock InventoryEventType = "inventory.stock.out_of_stock" StockLowStock InventoryEventType = "inventory.stock.low_stock" InventoryPaymentSuccess InventoryEventType = "inventory.payment.success" InventoryPaymentFailed InventoryEventType = "inventory.payment.failed" )
type InventoryPaymentFailedEvent ¶
type InventoryPaymentFailedEvent struct { InventoryEvent OrderNo string `json:"order_no"` PaymentNo string `json:"payment_no"` Items []StockItem `json:"items"` ReleaseTime time.Time `json:"release_time"` Reason string `json:"reason"` }
InventoryPaymentFailedEvent represents inventory release after payment failure
func (*InventoryPaymentFailedEvent) Validate ¶
func (e *InventoryPaymentFailedEvent) Validate() error
type InventoryPaymentSuccessEvent ¶
type InventoryPaymentSuccessEvent struct { InventoryEvent OrderNo string `json:"order_no"` PaymentNo string `json:"payment_no"` Items []StockItem `json:"items"` DeductTime time.Time `json:"deduct_time"` }
InventoryPaymentSuccessEvent represents inventory update after successful payment
func (*InventoryPaymentSuccessEvent) Validate ¶
func (e *InventoryPaymentSuccessEvent) Validate() error
Add validation methods
type MarketingEvent ¶
type MarketingEvent struct { Type MarketingEventType `json:"type"` UserID int64 `json:"user_id"` Timestamp time.Time `json:"timestamp"` }
MarketingEvent represents the base marketing event structure
type MarketingEventType ¶
type MarketingEventType string
const ( // Coupon events CouponIssued MarketingEventType = "marketing.coupon.issued" CouponUsed MarketingEventType = "marketing.coupon.used" CouponExpired MarketingEventType = "marketing.coupon.expired" CouponCancelled MarketingEventType = "marketing.coupon.cancelled" // Promotion events PromotionStarted MarketingEventType = "marketing.promotion.started" PromotionEnded MarketingEventType = "marketing.promotion.ended" PromotionApplied MarketingEventType = "marketing.promotion.applied" // Points events PointsEarned MarketingEventType = "marketing.points.earned" PointsUsed MarketingEventType = "marketing.points.used" PointsExpired MarketingEventType = "marketing.points.expired" PointsRefunded MarketingEventType = "marketing.points.refunded" MarketingPaymentSuccess MarketingEventType = "marketing.payment.success" MarketingPaymentFailed MarketingEventType = "marketing.payment.failed" )
type MarketingPaymentFailedEvent ¶
type MarketingPaymentFailedEvent struct { MarketingEvent OrderNo string `json:"order_no"` PaymentNo string `json:"payment_no"` Reason string `json:"reason"` }
MarketingPaymentFailedEvent represents marketing rollback after payment failure
func (*MarketingPaymentFailedEvent) Validate ¶
func (e *MarketingPaymentFailedEvent) Validate() error
type MarketingPaymentSuccessEvent ¶
type MarketingPaymentSuccessEvent struct { MarketingEvent OrderNo string `json:"order_no"` PaymentNo string `json:"payment_no"` Amount float64 `json:"amount"` RewardPoints int64 `json:"reward_points,omitempty"` CouponID int64 `json:"coupon_id,omitempty"` }
MarketingPaymentSuccessEvent represents marketing actions after payment success
func (*MarketingPaymentSuccessEvent) Validate ¶
func (e *MarketingPaymentSuccessEvent) Validate() error
type MessageBatchEvent ¶
type MessageBatchEvent struct { MessageEvent BatchID string `json:"batch_id"` Total int32 `json:"total"` Completed int32 `json:"completed"` Failed int32 `json:"failed"` Status string `json:"status"` }
MessageBatchEvent represents batch message events
func (*MessageBatchEvent) Validate ¶
func (e *MessageBatchEvent) Validate() error
type MessageEvent ¶
type MessageEvent struct { Type MessageEventType `json:"type"` UserID int64 `json:"user_id"` Timestamp time.Time `json:"timestamp"` }
MessageEvent represents the base message event structure
type MessageEventSentEvent ¶
type MessageEventSentEvent struct { MessageEvent MessageID string `json:"message_id"` Channel string `json:"channel"` // sms, email, push, etc Content string `json:"content"` Recipient string `json:"recipient"` Status string `json:"status"` Variables map[string]string `json:"variables,omitempty"` }
MessageEventSentEvent represents a sent message event
func (*MessageEventSentEvent) Validate ¶
func (e *MessageEventSentEvent) Validate() error
Add validation methods
type MessageEventType ¶
type MessageEventType string
const ( // System message events MessageEventSent MessageEventType = "message.event.sent" MessageEventReceived MessageEventType = "message.event.received" MessageEventFailed MessageEventType = "message.event.failed" // Template message events MessageTemplateCreated MessageEventType = "message.template.created" MessageTemplateUpdated MessageEventType = "message.template.updated" MessageTemplateDeleted MessageEventType = "message.template.deleted" // Batch message events MessageBatchCreated MessageEventType = "message.batch.created" MessageBatchProcessing MessageEventType = "message.batch.processing" MessageBatchCompleted MessageEventType = "message.batch.completed" MessageBatchFailed MessageEventType = "message.batch.failed" // Payment related message events MessagePaymentSuccess MessageEventType = "message.payment.success" MessagePaymentFailed MessageEventType = "message.payment.failed" )
type MessagePaymentFailedEvent ¶
type MessagePaymentFailedEvent struct { MessageEvent OrderNo string `json:"order_no"` PaymentNo string `json:"payment_no"` Amount float64 `json:"amount"` Reason string `json:"reason"` Channel string `json:"channel"` TemplateID int64 `json:"template_id"` }
MessagePaymentFailedEvent represents payment failure notification
func (*MessagePaymentFailedEvent) Validate ¶
func (e *MessagePaymentFailedEvent) Validate() error
type MessagePaymentSuccessEvent ¶
type MessagePaymentSuccessEvent struct { MessageEvent OrderNo string `json:"order_no"` PaymentNo string `json:"payment_no"` Amount float64 `json:"amount"` Channel string `json:"channel"` TemplateID int64 `json:"template_id"` }
MessagePaymentSuccessEvent represents payment success notification
func (*MessagePaymentSuccessEvent) Validate ¶
func (e *MessagePaymentSuccessEvent) Validate() error
type MessageTemplate ¶
type MessageTemplate struct { TemplateID int64 `json:"template_id"` TemplateCode string `json:"template_code"` Content string `json:"content"` Variables map[string]string `json:"variables"` }
MessageTemplate represents a message template
type MessageTemplateEvent ¶
type MessageTemplateEvent struct { MessageEvent Template MessageTemplate `json:"template"` Action string `json:"action"` // created, updated, deleted }
MessageTemplateEvent represents template related events
func (*MessageTemplateEvent) Validate ¶
func (e *MessageTemplateEvent) Validate() error
type Metadata ¶
type Metadata struct { TraceID string `json:"trace_id"` // Unique trace ID for the event Source string `json:"source"` // Source service name Timestamp time.Time `json:"timestamp"` // Event creation time Version string `json:"version"` // Event version Headers map[string]string `json:"headers"` // Custom headers RetryCount int `json:"retry_count"` // Number of retries DeliveryMode string `json:"delivery_mode"` // persistent or non-persistent }
Metadata represents event metadata for tracing and processing
type MetadataBuilder ¶
type MetadataBuilder struct {
// contains filtered or unexported fields
}
MetadataBuilder helps build metadata with a fluent interface
func NewMetadataBuilder ¶
func NewMetadataBuilder() *MetadataBuilder
NewMetadataBuilder creates a new MetadataBuilder
type NonRetryableError ¶
type NonRetryableError struct {
*EventError
}
NonRetryableError indicates the error cannot be retried
type OrderAlertEvent ¶
type OrderAlertEvent struct { OrderEvent AlertType string `json:"alert_type"` AlertLevel string `json:"alert_level"` Message string `json:"message"` }
type OrderCancelledEvent ¶
type OrderCancelledEvent struct { OrderEvent Reason string `json:"reason"` }
OrderCancelledEvent represents order cancellation event
type OrderCompletedEvent ¶
type OrderCompletedEvent struct { OrderEvent ReceiveTime time.Time `json:"receive_time"` }
OrderCompletedEvent represents order completion event
type OrderCreatedEvent ¶
type OrderCreatedEvent struct { OrderEvent Items []OrderItem `json:"items"` TotalAmount float64 `json:"total_amount"` PayAmount float64 `json:"pay_amount"` Address string `json:"address"` Receiver string `json:"receiver"` Phone string `json:"phone"` }
OrderCreatedEvent represents order creation event
type OrderEvent ¶
type OrderEvent struct { Type OrderEventType `json:"type"` OrderNo string `json:"order_no"` UserID int64 `json:"user_id"` Timestamp time.Time `json:"timestamp"` }
OrderEvent represents the base order event structure
type OrderEventType ¶
type OrderEventType string
const ( OrderCreated OrderEventType = "order.created" OrderPaid OrderEventType = "order.paid" OrderCancelled OrderEventType = "order.cancelled" OrderShipped OrderEventType = "order.shipped" OrderCompleted OrderEventType = "order.completed" OrderRefunded OrderEventType = "order.refunded" )
type OrderItem ¶
type OrderItem struct { ProductID int64 `json:"product_id"` SkuID int64 `json:"sku_id"` Quantity int32 `json:"quantity"` Price float64 `json:"price"` }
OrderItem represents an item in the order
type OrderPaidEvent ¶
type OrderPaidEvent struct { OrderEvent PaymentNo string `json:"payment_no"` PaymentMethod int32 `json:"payment_method"` PayAmount float64 `json:"pay_amount"` }
OrderPaidEvent represents order payment event
type OrderPaymentFailedEvent ¶
type OrderPaymentFailedEvent struct { OrderEvent PaymentNo string `json:"payment_no"` Amount float64 `json:"amount"` Reason string `json:"reason"` ErrorCode string `json:"error_code"` }
OrderPaymentFailedEvent represents failed payment notification for order
type OrderPaymentRefundedEvent ¶
type OrderPaymentRefundedEvent struct { OrderEvent PaymentNo string `json:"payment_no"` RefundNo string `json:"refund_no"` RefundAmount float64 `json:"refund_amount"` Reason string `json:"reason"` RefundTime time.Time `json:"refund_time"` }
OrderPaymentRefundedEvent represents refund notification for order
type OrderPaymentSuccessEvent ¶
type OrderPaymentSuccessEvent struct { OrderEvent PaymentNo string `json:"payment_no"` PaymentMethod int32 `json:"payment_method"` Amount float64 `json:"amount"` PaidTime time.Time `json:"paid_time"` }
OrderPaymentSuccessEvent represents successful payment notification for order
type OrderRefundedEvent ¶
type OrderRefundedEvent struct { OrderEvent Items []OrderItem `json:"items"` RefundNo string `json:"refund_no"` RefundType int32 `json:"refund_type"` Amount float64 `json:"amount"` Reason string `json:"reason"` }
OrderRefundedEvent represents order refund event
type OrderShippedEvent ¶
type OrderShippedEvent struct { OrderEvent ShippingNo string `json:"shipping_no"` Company string `json:"company"` }
OrderShippedEvent represents order shipping event
type OrderStatusChangedEvent ¶
type OrderStatusChangedEvent struct { OrderEvent OldStatus int32 `json:"old_status"` NewStatus int32 `json:"new_status"` EventType OrderStatusEventType `json:"event_type"` PaymentNo string `json:"payment_no,omitempty"` ShippingNo string `json:"shipping_no,omitempty"` RefundNo string `json:"refund_no,omitempty"` Reason string `json:"reason,omitempty"` }
Enhanced OrderStatusChangedEvent
type OrderStatusEventType ¶
type OrderStatusEventType string
OrderStatusEventType represents the specific type of status change
const ( OrderStatusPaid OrderStatusEventType = "order.status.paid" OrderStatusShipped OrderStatusEventType = "order.status.shipped" OrderStatusReceived OrderStatusEventType = "order.status.received" OrderStatusCanceled OrderStatusEventType = "order.status.canceled" OrderStatusRefunding OrderStatusEventType = "order.status.refunding" )
type PaymentCreatedEvent ¶
type PaymentCreatedEvent struct { PaymentEvent Amount float64 `json:"amount"` PaymentMethod int32 `json:"payment_method"` PayURL string `json:"pay_url"` }
PaymentCreatedEvent represents payment creation
type PaymentEvent ¶
type PaymentEvent struct { Type PaymentEventType `json:"type"` OrderNo string `json:"order_no"` PaymentNo string `json:"payment_no"` Timestamp time.Time `json:"timestamp"` }
PaymentEvent represents the base payment event structure
type PaymentEventType ¶
type PaymentEventType string
const ( PaymentCreated PaymentEventType = "payment.created" PaymentSuccess PaymentEventType = "payment.success" PaymentFailed PaymentEventType = "payment.failed" PaymentRefund PaymentEventType = "payment.refund" PaymentVerified PaymentEventType = "payment.verified" )
type PaymentFailedEvent ¶
type PaymentFailedEvent struct { PaymentEvent Amount float64 `json:"amount"` Reason string `json:"reason"` ErrorCode string `json:"error_code"` }
PaymentFailedEvent represents failed payment
type PaymentRefundEvent ¶
type PaymentRefundEvent struct { PaymentEvent RefundNo string `json:"refund_no"` RefundAmount float64 `json:"refund_amount"` Reason string `json:"reason"` RefundTime time.Time `json:"refund_time"` }
PaymentRefundEvent represents refund event
type PaymentSuccessEvent ¶
type PaymentSuccessEvent struct { PaymentEvent Amount float64 `json:"amount"` PaymentMethod int32 `json:"payment_method"` PaidTime time.Time `json:"paid_time"` }
PaymentSuccessEvent represents successful payment
type PaymentVerificationEvent ¶
type PaymentVerificationEvent struct { PaymentEvent Verified bool `json:"verified"` Message string `json:"message"` }
PaymentVerificationEvent represents payment verification
type PointsEvent ¶
type PointsEvent struct { MarketingEvent Points int64 `json:"points"` Balance int64 `json:"balance"` Source string `json:"source"` OrderNo string `json:"order_no,omitempty"` Reason string `json:"reason,omitempty"` }
PointsEvent represents points-related events
func (*PointsEvent) Validate ¶
func (e *PointsEvent) Validate() error
type PromotionEvent ¶
type PromotionEvent struct { MarketingEvent PromotionID int64 `json:"promotion_id"` PromotionType int32 `json:"promotion_type"` Discount float64 `json:"discount,omitempty"` OrderNo string `json:"order_no,omitempty"` }
PromotionEvent represents promotion-related events
func (*PromotionEvent) Validate ¶
func (e *PromotionEvent) Validate() error
type RetryableError ¶
type RetryableError struct {
*EventError
}
RetryableError indicates the error can be retried
type StockAlertEvent ¶
type StockAlertEvent struct { InventoryEvent SkuID int64 `json:"sku_id"` Current int32 `json:"current"` Threshold int32 `json:"threshold"` }
StockAlertEvent represents stock alert event
type StockCheckedEvent ¶
type StockCheckedEvent struct { InventoryEvent OrderNo string `json:"order_no"` Items []StockItem `json:"items"` Success bool `json:"success"` Reason string `json:"reason,omitempty"` }
StockCheckedEvent represents stock check result event
type StockDeductedEvent ¶
type StockDeductedEvent struct { InventoryEvent OrderNo string `json:"order_no"` Items []StockItem `json:"items"` }
StockDeductedEvent represents stock deduction event
type StockLockedEvent ¶
type StockLockedEvent struct { InventoryEvent OrderNo string `json:"order_no"` Items []StockItem `json:"items"` }
StockLockedEvent represents stock locking event
func (*StockLockedEvent) Validate ¶
func (e *StockLockedEvent) Validate() error
Add validation methods
type StockLowStockEvent ¶
type StockLowStockEvent struct { InventoryEvent SkuID int64 `json:"sku_id"` Quantity int32 `json:"quantity"` Threshold int32 `json:"threshold"` }
type StockOutOfStockEvent ¶
type StockOutOfStockEvent struct { InventoryEvent SkuID int64 `json:"sku_id"` Quantity int32 `json:"quantity"` Reason string `json:"reason"` }
type StockReservedEvent ¶
type StockReservedEvent struct { InventoryEvent OrderNo string `json:"order_no"` Items []StockItem `json:"items"` ExpireTime time.Time `json:"expire_time"` }
StockReservedEvent represents stock reservation event
type StockUnlockedEvent ¶
type StockUnlockedEvent struct { InventoryEvent OrderNo string `json:"order_no"` Items []StockItem `json:"items"` }
StockUnlockedEvent represents stock unlocking event
type StockUpdatedEvent ¶
type StockUpdatedEvent struct { InventoryEvent SkuID int64 `json:"sku_id"` OldQuantity int32 `json:"old_quantity"` NewQuantity int32 `json:"new_quantity"` Reason string `json:"reason"` }
func (*StockUpdatedEvent) Validate ¶
func (e *StockUpdatedEvent) Validate() error
Add validation methods for new events