hook

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FixedError

func FixedError(err error) ent.Hook

FixedError is a hook returning a fixed error.

func If

func If(hk ent.Hook, cond Condition) ent.Hook

If executes the given hook under condition.

hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...)))

func On

func On(hk ent.Hook, op ent.Op) ent.Hook

On executes the given hook only for the given operation.

hook.On(Log, ent.Delete|ent.Create)

func Reject

func Reject(op ent.Op) ent.Hook

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 Unless

func Unless(hk ent.Hook, op ent.Op) ent.Hook

Unless skips the given hook only for the given operation.

hook.Unless(Log, ent.Update|ent.UpdateOne)

Types

type AdministratorFunc

type AdministratorFunc func(context.Context, *ent.AdministratorMutation) (ent.Value, error)

The AdministratorFunc type is an adapter to allow the use of ordinary function as Administrator mutator.

func (AdministratorFunc) Mutate

Mutate calls f(ctx, m).

type Chain

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

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.

func NewChain

func NewChain(hooks ...ent.Hook) Chain

NewChain creates a new chain of hooks.

func (Chain) Append

func (c Chain) Append(hooks ...ent.Hook) Chain

Append extends a chain, adding the specified hook as the last ones in the mutation flow.

func (Chain) Extend

func (c Chain) Extend(chain Chain) Chain

Extend extends a chain, adding the specified chain as the last ones in the mutation flow.

func (Chain) Hook

func (c Chain) Hook() ent.Hook

Hook chains the list of hooks and returns the final hook.

type Condition

type Condition func(context.Context, ent.Mutation) bool

Condition is a hook condition function.

func And

func And(first, second Condition, rest ...Condition) Condition

And groups conditions with the AND operator.

func HasAddedFields

func HasAddedFields(field string, fields ...string) Condition

HasAddedFields is a condition validating `.AddedField` on fields.

func HasClearedFields

func HasClearedFields(field string, fields ...string) Condition

HasClearedFields is a condition validating `.FieldCleared` on fields.

func HasFields

func HasFields(field string, fields ...string) Condition

HasFields is a condition validating `.Field` on fields.

func HasOp

func HasOp(op ent.Op) Condition

HasOp is a condition testing mutation operation.

func Not

func Not(cond Condition) Condition

Not negates a given condition.

func Or

func Or(first, second Condition, rest ...Condition) Condition

Or groups conditions with the OR operator.

type DeletedVlanLogFunc

type DeletedVlanLogFunc func(context.Context, *ent.DeletedVlanLogMutation) (ent.Value, error)

The DeletedVlanLogFunc type is an adapter to allow the use of ordinary function as DeletedVlanLog mutator.

func (DeletedVlanLogFunc) Mutate

Mutate calls f(ctx, m).

type DeviceFunc

type DeviceFunc func(context.Context, *ent.DeviceMutation) (ent.Value, error)

The DeviceFunc type is an adapter to allow the use of ordinary function as Device mutator.

func (DeviceFunc) Mutate

func (f DeviceFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error)

Mutate calls f(ctx, m).

type DevicePlatformFunc

type DevicePlatformFunc func(context.Context, *ent.DevicePlatformMutation) (ent.Value, error)

The DevicePlatformFunc type is an adapter to allow the use of ordinary function as DevicePlatform mutator.

func (DevicePlatformFunc) Mutate

Mutate calls f(ctx, m).

type DeviceTypeFunc

type DeviceTypeFunc func(context.Context, *ent.DeviceTypeMutation) (ent.Value, error)

The DeviceTypeFunc type is an adapter to allow the use of ordinary function as DeviceType mutator.

func (DeviceTypeFunc) Mutate

func (f DeviceTypeFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error)

Mutate calls f(ctx, m).

type IPAddressFunc added in v0.2.0

type IPAddressFunc func(context.Context, *ent.IPAddressMutation) (ent.Value, error)

The IPAddressFunc type is an adapter to allow the use of ordinary function as IPAddress mutator.

func (IPAddressFunc) Mutate added in v0.2.0

func (f IPAddressFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error)

Mutate calls f(ctx, m).

type IPStaticRoutingTableFunc added in v0.2.0

type IPStaticRoutingTableFunc func(context.Context, *ent.IPStaticRoutingTableMutation) (ent.Value, error)

The IPStaticRoutingTableFunc type is an adapter to allow the use of ordinary function as IPStaticRoutingTable mutator.

func (IPStaticRoutingTableFunc) Mutate added in v0.2.0

Mutate calls f(ctx, m).

type NetInterfaceFunc

type NetInterfaceFunc func(context.Context, *ent.NetInterfaceMutation) (ent.Value, error)

The NetInterfaceFunc type is an adapter to allow the use of ordinary function as NetInterface mutator.

func (NetInterfaceFunc) Mutate

func (f NetInterfaceFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error)

Mutate calls f(ctx, m).

type NetInterfaceLayerFunc added in v0.2.0

type NetInterfaceLayerFunc func(context.Context, *ent.NetInterfaceLayerMutation) (ent.Value, error)

The NetInterfaceLayerFunc type is an adapter to allow the use of ordinary function as NetInterfaceLayer mutator.

func (NetInterfaceLayerFunc) Mutate added in v0.2.0

Mutate calls f(ctx, m).

type NetInterfaceModeFunc

type NetInterfaceModeFunc func(context.Context, *ent.NetInterfaceModeMutation) (ent.Value, error)

The NetInterfaceModeFunc type is an adapter to allow the use of ordinary function as NetInterfaceMode mutator.

func (NetInterfaceModeFunc) Mutate

Mutate calls f(ctx, m).

type NetTopologyDeviceMapFunc

type NetTopologyDeviceMapFunc func(context.Context, *ent.NetTopologyDeviceMapMutation) (ent.Value, error)

The NetTopologyDeviceMapFunc type is an adapter to allow the use of ordinary function as NetTopologyDeviceMap mutator.

func (NetTopologyDeviceMapFunc) Mutate

Mutate calls f(ctx, m).

type NetTopologyFunc

type NetTopologyFunc func(context.Context, *ent.NetTopologyMutation) (ent.Value, error)

The NetTopologyFunc type is an adapter to allow the use of ordinary function as NetTopology mutator.

func (NetTopologyFunc) Mutate

func (f NetTopologyFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error)

Mutate calls f(ctx, m).

type PortChannelInterfaceFunc added in v0.2.0

type PortChannelInterfaceFunc func(context.Context, *ent.PortChannelInterfaceMutation) (ent.Value, error)

The PortChannelInterfaceFunc type is an adapter to allow the use of ordinary function as PortChannelInterface mutator.

func (PortChannelInterfaceFunc) Mutate added in v0.2.0

Mutate calls f(ctx, m).

type VlanFunc

type VlanFunc func(context.Context, *ent.VlanMutation) (ent.Value, error)

The VlanFunc type is an adapter to allow the use of ordinary function as Vlan mutator.

func (VlanFunc) Mutate

func (f VlanFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error)

Mutate calls f(ctx, m).

Jump to

Keyboard shortcuts

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