// Code generated by ent, DO NOT EDIT. package hook import ( "context" "fmt" "wechat-api/ent" ) // The AgentFunc type is an adapter to allow the use of ordinary // function as Agent mutator. type AgentFunc func(context.Context, *ent.AgentMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f AgentFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.AgentMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AgentMutation", m) } // The AgentBaseFunc type is an adapter to allow the use of ordinary // function as AgentBase mutator. type AgentBaseFunc func(context.Context, *ent.AgentBaseMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f AgentBaseFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.AgentBaseMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AgentBaseMutation", m) } // The AliyunAvatarFunc type is an adapter to allow the use of ordinary // function as AliyunAvatar mutator. type AliyunAvatarFunc func(context.Context, *ent.AliyunAvatarMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f AliyunAvatarFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.AliyunAvatarMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AliyunAvatarMutation", m) } // The AllocAgentFunc type is an adapter to allow the use of ordinary // function as AllocAgent mutator. type AllocAgentFunc func(context.Context, *ent.AllocAgentMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f AllocAgentFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.AllocAgentMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AllocAgentMutation", m) } // The BatchMsgFunc type is an adapter to allow the use of ordinary // function as BatchMsg mutator. type BatchMsgFunc func(context.Context, *ent.BatchMsgMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f BatchMsgFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.BatchMsgMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.BatchMsgMutation", m) } // The CategoryFunc type is an adapter to allow the use of ordinary // function as Category mutator. type CategoryFunc func(context.Context, *ent.CategoryMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f CategoryFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.CategoryMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.CategoryMutation", m) } // The ChatRecordsFunc type is an adapter to allow the use of ordinary // function as ChatRecords mutator. type ChatRecordsFunc func(context.Context, *ent.ChatRecordsMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f ChatRecordsFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.ChatRecordsMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ChatRecordsMutation", m) } // The ChatSessionFunc type is an adapter to allow the use of ordinary // function as ChatSession mutator. type ChatSessionFunc func(context.Context, *ent.ChatSessionMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f ChatSessionFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.ChatSessionMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ChatSessionMutation", m) } // The ContactFunc type is an adapter to allow the use of ordinary // function as Contact mutator. type ContactFunc func(context.Context, *ent.ContactMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f ContactFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.ContactMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ContactMutation", m) } // The CreditBalanceFunc type is an adapter to allow the use of ordinary // function as CreditBalance mutator. type CreditBalanceFunc func(context.Context, *ent.CreditBalanceMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f CreditBalanceFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.CreditBalanceMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.CreditBalanceMutation", m) } // The CreditUsageFunc type is an adapter to allow the use of ordinary // function as CreditUsage mutator. type CreditUsageFunc func(context.Context, *ent.CreditUsageMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f CreditUsageFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.CreditUsageMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.CreditUsageMutation", m) } // The EmployeeFunc type is an adapter to allow the use of ordinary // function as Employee mutator. type EmployeeFunc func(context.Context, *ent.EmployeeMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f EmployeeFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.EmployeeMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.EmployeeMutation", m) } // The EmployeeConfigFunc type is an adapter to allow the use of ordinary // function as EmployeeConfig mutator. type EmployeeConfigFunc func(context.Context, *ent.EmployeeConfigMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f EmployeeConfigFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.EmployeeConfigMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.EmployeeConfigMutation", m) } // The LabelFunc type is an adapter to allow the use of ordinary // function as Label mutator. type LabelFunc func(context.Context, *ent.LabelMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f LabelFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.LabelMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.LabelMutation", m) } // The LabelRelationshipFunc type is an adapter to allow the use of ordinary // function as LabelRelationship mutator. type LabelRelationshipFunc func(context.Context, *ent.LabelRelationshipMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f LabelRelationshipFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.LabelRelationshipMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.LabelRelationshipMutation", m) } // The LabelTaggingFunc type is an adapter to allow the use of ordinary // function as LabelTagging mutator. type LabelTaggingFunc func(context.Context, *ent.LabelTaggingMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f LabelTaggingFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.LabelTaggingMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.LabelTaggingMutation", m) } // The MessageFunc type is an adapter to allow the use of ordinary // function as Message mutator. type MessageFunc func(context.Context, *ent.MessageMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f MessageFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.MessageMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.MessageMutation", m) } // The MessageRecordsFunc type is an adapter to allow the use of ordinary // function as MessageRecords mutator. type MessageRecordsFunc func(context.Context, *ent.MessageRecordsMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f MessageRecordsFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.MessageRecordsMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.MessageRecordsMutation", m) } // The MsgFunc type is an adapter to allow the use of ordinary // function as Msg mutator. type MsgFunc func(context.Context, *ent.MsgMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f MsgFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.MsgMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.MsgMutation", m) } // The PayRechargeFunc type is an adapter to allow the use of ordinary // function as PayRecharge mutator. type PayRechargeFunc func(context.Context, *ent.PayRechargeMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f PayRechargeFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.PayRechargeMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.PayRechargeMutation", m) } // The ServerFunc type is an adapter to allow the use of ordinary // function as Server mutator. type ServerFunc func(context.Context, *ent.ServerMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f ServerFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.ServerMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ServerMutation", m) } // The SopNodeFunc type is an adapter to allow the use of ordinary // function as SopNode mutator. type SopNodeFunc func(context.Context, *ent.SopNodeMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f SopNodeFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.SopNodeMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SopNodeMutation", m) } // The SopStageFunc type is an adapter to allow the use of ordinary // function as SopStage mutator. type SopStageFunc func(context.Context, *ent.SopStageMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f SopStageFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.SopStageMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SopStageMutation", m) } // The SopTaskFunc type is an adapter to allow the use of ordinary // function as SopTask mutator. type SopTaskFunc func(context.Context, *ent.SopTaskMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f SopTaskFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.SopTaskMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SopTaskMutation", m) } // The TokenFunc type is an adapter to allow the use of ordinary // function as Token mutator. type TokenFunc func(context.Context, *ent.TokenMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f TokenFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.TokenMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.TokenMutation", m) } // The TutorialFunc type is an adapter to allow the use of ordinary // function as Tutorial mutator. type TutorialFunc func(context.Context, *ent.TutorialMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f TutorialFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.TutorialMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.TutorialMutation", m) } // The UsageDetailFunc type is an adapter to allow the use of ordinary // function as UsageDetail mutator. type UsageDetailFunc func(context.Context, *ent.UsageDetailMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f UsageDetailFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.UsageDetailMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UsageDetailMutation", m) } // The UsageStatisticDayFunc type is an adapter to allow the use of ordinary // function as UsageStatisticDay mutator. type UsageStatisticDayFunc func(context.Context, *ent.UsageStatisticDayMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f UsageStatisticDayFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.UsageStatisticDayMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UsageStatisticDayMutation", m) } // The UsageStatisticHourFunc type is an adapter to allow the use of ordinary // function as UsageStatisticHour mutator. type UsageStatisticHourFunc func(context.Context, *ent.UsageStatisticHourMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f UsageStatisticHourFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.UsageStatisticHourMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UsageStatisticHourMutation", m) } // The UsageStatisticMonthFunc type is an adapter to allow the use of ordinary // function as UsageStatisticMonth mutator. type UsageStatisticMonthFunc func(context.Context, *ent.UsageStatisticMonthMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f UsageStatisticMonthFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.UsageStatisticMonthMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UsageStatisticMonthMutation", m) } // The UsageTotalFunc type is an adapter to allow the use of ordinary // function as UsageTotal mutator. type UsageTotalFunc func(context.Context, *ent.UsageTotalMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f UsageTotalFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.UsageTotalMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UsageTotalMutation", m) } // The WhatsappFunc type is an adapter to allow the use of ordinary // function as Whatsapp mutator. type WhatsappFunc func(context.Context, *ent.WhatsappMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f WhatsappFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.WhatsappMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.WhatsappMutation", m) } // The WhatsappChannelFunc type is an adapter to allow the use of ordinary // function as WhatsappChannel mutator. type WhatsappChannelFunc func(context.Context, *ent.WhatsappChannelMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f WhatsappChannelFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.WhatsappChannelMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.WhatsappChannelMutation", m) } // The WorkExperienceFunc type is an adapter to allow the use of ordinary // function as WorkExperience mutator. type WorkExperienceFunc func(context.Context, *ent.WorkExperienceMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f WorkExperienceFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.WorkExperienceMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.WorkExperienceMutation", m) } // The WpChatroomFunc type is an adapter to allow the use of ordinary // function as WpChatroom mutator. type WpChatroomFunc func(context.Context, *ent.WpChatroomMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f WpChatroomFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.WpChatroomMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.WpChatroomMutation", m) } // The WpChatroomMemberFunc type is an adapter to allow the use of ordinary // function as WpChatroomMember mutator. type WpChatroomMemberFunc func(context.Context, *ent.WpChatroomMemberMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f WpChatroomMemberFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.WpChatroomMemberMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.WpChatroomMemberMutation", m) } // The WxFunc type is an adapter to allow the use of ordinary // function as Wx mutator. type WxFunc func(context.Context, *ent.WxMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f WxFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.WxMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.WxMutation", m) } // The WxCardFunc type is an adapter to allow the use of ordinary // function as WxCard mutator. type WxCardFunc func(context.Context, *ent.WxCardMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f WxCardFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.WxCardMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.WxCardMutation", m) } // The WxCardUserFunc type is an adapter to allow the use of ordinary // function as WxCardUser mutator. type WxCardUserFunc func(context.Context, *ent.WxCardUserMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f WxCardUserFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.WxCardUserMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.WxCardUserMutation", m) } // The WxCardVisitFunc type is an adapter to allow the use of ordinary // function as WxCardVisit mutator. type WxCardVisitFunc func(context.Context, *ent.WxCardVisitMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f WxCardVisitFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { if mv, ok := m.(*ent.WxCardVisitMutation); ok { return f(ctx, mv) } return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.WxCardVisitMutation", m) } // Condition is a hook condition function. type Condition func(context.Context, ent.Mutation) bool // And groups conditions with the AND operator. func And(first, second Condition, rest ...Condition) Condition { return func(ctx context.Context, m ent.Mutation) bool { if !first(ctx, m) || !second(ctx, m) { return false } for _, cond := range rest { if !cond(ctx, m) { return false } } return true } } // Or groups conditions with the OR operator. func Or(first, second Condition, rest ...Condition) Condition { return func(ctx context.Context, m ent.Mutation) bool { if first(ctx, m) || second(ctx, m) { return true } for _, cond := range rest { if cond(ctx, m) { return true } } return false } } // Not negates a given condition. func Not(cond Condition) Condition { return func(ctx context.Context, m ent.Mutation) bool { return !cond(ctx, m) } } // HasOp is a condition testing mutation operation. func HasOp(op ent.Op) Condition { return func(_ context.Context, m ent.Mutation) bool { return m.Op().Is(op) } } // HasAddedFields is a condition validating `.AddedField` on fields. func HasAddedFields(field string, fields ...string) Condition { return func(_ context.Context, m ent.Mutation) bool { if _, exists := m.AddedField(field); !exists { return false } for _, field := range fields { if _, exists := m.AddedField(field); !exists { return false } } return true } } // HasClearedFields is a condition validating `.FieldCleared` on fields. func HasClearedFields(field string, fields ...string) Condition { return func(_ context.Context, m ent.Mutation) bool { if exists := m.FieldCleared(field); !exists { return false } for _, field := range fields { if exists := m.FieldCleared(field); !exists { return false } } return true } } // HasFields is a condition validating `.Field` on fields. func HasFields(field string, fields ...string) Condition { return func(_ context.Context, m ent.Mutation) bool { if _, exists := m.Field(field); !exists { return false } for _, field := range fields { if _, exists := m.Field(field); !exists { return false } } return true } } // If executes the given hook under condition. // // hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...))) func If(hk ent.Hook, cond Condition) ent.Hook { return func(next ent.Mutator) ent.Mutator { return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) { if cond(ctx, m) { return hk(next).Mutate(ctx, m) } return next.Mutate(ctx, m) }) } } // On executes the given hook only for the given operation. // // hook.On(Log, ent.Delete|ent.Create) func On(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, HasOp(op)) } // Unless skips the given hook only for the given operation. // // hook.Unless(Log, ent.Update|ent.UpdateOne) func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } // FixedError is a hook returning a fixed error. func FixedError(err error) ent.Hook { return func(ent.Mutator) ent.Mutator { return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { return nil, err }) } } // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { // return []ent.Hook{ // Reject(ent.Delete|ent.Update), // } // } func Reject(op ent.Op) ent.Hook { hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } // Chain acts as a list of hooks and is effectively immutable. // Once created, it will always hold the same set of hooks in the same order. type Chain struct { hooks []ent.Hook } // NewChain creates a new chain of hooks. func NewChain(hooks ...ent.Hook) Chain { return Chain{append([]ent.Hook(nil), hooks...)} } // Hook chains the list of hooks and returns the final hook. func (c Chain) Hook() ent.Hook { return func(mutator ent.Mutator) ent.Mutator { for i := len(c.hooks) - 1; i >= 0; i-- { mutator = c.hooks[i](mutator) } return mutator } } // Append extends a chain, adding the specified hook // as the last ones in the mutation flow. func (c Chain) Append(hooks ...ent.Hook) Chain { newHooks := make([]ent.Hook, 0, len(c.hooks)+len(hooks)) newHooks = append(newHooks, c.hooks...) newHooks = append(newHooks, hooks...) return Chain{newHooks} } // Extend extends a chain, adding the specified chain // as the last ones in the mutation flow. func (c Chain) Extend(chain Chain) Chain { return c.Append(chain.hooks...) }