Documentation
¶
Overview ¶
Package hooks provides lifecycle hook management for DynamORM model operations with cost tracking integration.
Index ¶
- func AuditHook(ctx context.Context, model any) error
- func CacheInvalidationHook(ctx context.Context, model any) error
- func Execute(ctx context.Context, model any, hookType HookType) error
- func NotificationHook(ctx context.Context, model any) error
- func Register(modelType reflect.Type, hookType HookType, fn HookFunc)
- func RegisterAsync(modelType reflect.Type, hookType HookType, fn AsyncHookFunc)
- func RegisterConditional(modelType reflect.Type, hookType HookType, ...)
- func SearchIndexHook(ctx context.Context, model any) error
- func SetGlobalRegistry(registry *HookRegistry)
- func TimestampHook(_ context.Context, model any) error
- func ValidationHook(_ context.Context, model any) error
- type AsyncHookFunc
- type ConditionalHookFunc
- type FavoriteModel
- type FollowModel
- type HookFunc
- type HookRegistry
- func (hr *HookRegistry) Clear(modelType reflect.Type)
- func (hr *HookRegistry) ClearAll()
- func (hr *HookRegistry) Execute(ctx context.Context, model any, hookType HookType) error
- func (hr *HookRegistry) GetRegisteredHooksCount(modelType reflect.Type, hookType HookType) int
- func (hr *HookRegistry) Register(modelType reflect.Type, hookType HookType, fn HookFunc)
- func (hr *HookRegistry) RegisterAsync(modelType reflect.Type, hookType HookType, fn AsyncHookFunc)
- func (hr *HookRegistry) RegisterConditional(modelType reflect.Type, hookType HookType, ...)
- type HookStats
- type HookStatsTracker
- type HookType
- type MentionModel
- type NotificationData
- type NotificationRepository
- type PollModel
- type ReblogModel
- type StatusModel
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CacheInvalidationHook ¶
CacheInvalidationHook invalidates relevant caches
func NotificationHook ¶
NotificationHook creates notifications based on model changes
func RegisterAsync ¶
func RegisterAsync(modelType reflect.Type, hookType HookType, fn AsyncHookFunc)
RegisterAsync registers an async hook with the global registry
func RegisterConditional ¶
func RegisterConditional(modelType reflect.Type, hookType HookType, condition func(ctx context.Context, model any) bool, fn HookFunc)
RegisterConditional registers a conditional hook with the global registry
func SearchIndexHook ¶
SearchIndexHook updates search indexes
func SetGlobalRegistry ¶
func SetGlobalRegistry(registry *HookRegistry)
SetGlobalRegistry sets the global hook registry instance
func TimestampHook ¶
TimestampHook updates timestamps on models
Types ¶
type AsyncHookFunc ¶
AsyncHookFunc is a function that gets executed asynchronously
type ConditionalHookFunc ¶
type ConditionalHookFunc struct {
Condition func(ctx context.Context, model any) bool
Hook HookFunc
}
ConditionalHookFunc is a hook function with a condition
type FavoriteModel ¶
FavoriteModel interface for favorite-related models
type FollowModel ¶
FollowModel interface for follow-related models
type HookRegistry ¶
type HookRegistry struct {
// contains filtered or unexported fields
}
HookRegistry manages all registered hooks
func GetGlobalRegistry ¶
func GetGlobalRegistry() *HookRegistry
GetGlobalRegistry returns the global hook registry instance
func NewHookRegistry ¶
func NewHookRegistry(logger *zap.Logger) *HookRegistry
NewHookRegistry creates a new hook registry
func (*HookRegistry) Clear ¶
func (hr *HookRegistry) Clear(modelType reflect.Type)
Clear removes all hooks for a model type
func (*HookRegistry) ClearAll ¶
func (hr *HookRegistry) ClearAll()
ClearAll removes all registered hooks
func (*HookRegistry) GetRegisteredHooksCount ¶
func (hr *HookRegistry) GetRegisteredHooksCount(modelType reflect.Type, hookType HookType) int
GetRegisteredHooksCount returns the number of registered hooks for a model type
func (*HookRegistry) Register ¶
func (hr *HookRegistry) Register(modelType reflect.Type, hookType HookType, fn HookFunc)
Register registers a synchronous hook for a model type
func (*HookRegistry) RegisterAsync ¶
func (hr *HookRegistry) RegisterAsync(modelType reflect.Type, hookType HookType, fn AsyncHookFunc)
RegisterAsync registers an asynchronous hook for a model type
type HookStats ¶
type HookStats struct {
TotalExecutions int64
TotalDuration time.Duration
ErrorCount int64
AverageDuration time.Duration
LastExecution time.Time
}
HookStats tracks execution statistics for hooks
type HookStatsTracker ¶
type HookStatsTracker struct {
// contains filtered or unexported fields
}
HookStatsTracker tracks statistics for hook executions
func GetGlobalStatsTracker ¶
func GetGlobalStatsTracker() *HookStatsTracker
GetGlobalStatsTracker returns the global hook statistics tracker
func NewHookStatsTracker ¶
func NewHookStatsTracker() *HookStatsTracker
NewHookStatsTracker creates a new hook statistics tracker
func (*HookStatsTracker) GetStats ¶
func (hst *HookStatsTracker) GetStats() map[string]*HookStats
GetStats returns statistics for all hooks
func (*HookStatsTracker) TrackExecution ¶
func (hst *HookStatsTracker) TrackExecution(modelType reflect.Type, hookType HookType, duration time.Duration, err error)
TrackExecution tracks the execution of a hook
type HookType ¶
type HookType string
HookType represents the type of lifecycle hook
const ( // BeforeCreate represents a before create hook BeforeCreate HookType = "before_create" // AfterCreate represents an after create hook AfterCreate HookType = "after_create" // BeforeUpdate represents a before update hook BeforeUpdate HookType = "before_update" // AfterUpdate represents an after update hook AfterUpdate HookType = "after_update" // BeforeDelete represents a before delete hook BeforeDelete HookType = "before_delete" // AfterDelete represents an after delete hook AfterDelete HookType = "after_delete" // AfterFind represents an after find hook AfterFind HookType = "after_find" // BeforeSave represents a before save hook BeforeSave HookType = "before_save" // AfterSave represents an after save hook AfterSave HookType = "after_save" )
type MentionModel ¶
MentionModel interface for mention-related models
type NotificationData ¶
type NotificationData struct {
Type string
UserID string
FromUser string
StatusID string
ErrorFields []zap.Field
}
NotificationData holds parameters for creating notifications
type NotificationRepository ¶
type NotificationRepository interface {
CreateNotification(ctx context.Context, notification any) error
GetUserPushSubscriptions(ctx context.Context, username string) ([]any, error)
SendPushNotification(ctx context.Context, username string, notification any) error
}
NotificationRepository interface for notification operations
type PollModel ¶
type PollModel interface {
GetPollID() string
GetAuthorID() string
GetVoterID() string
HasEnded() bool
}
PollModel interface for poll-related models
type ReblogModel ¶
ReblogModel interface for reblog-related models
type StatusModel ¶
StatusModel interface for status-related models