hook

package
v0.0.0-...-a1dc8d7 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 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) fluentv2.Hook

FixedError is a hook returning a fixed error.

func If

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

If executes the given hook under condition.

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

func On

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

On executes the given hook only for the given operation.

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

func Reject

func Reject(op fluentv2.Op) fluentv2.Hook

Reject returns a hook that rejects all operations that match op.

func (T) Hooks() []fluentv2.Hook {
	return []fluentv2.Hook{
		Reject(fluentv2.Delete|fluentv2.Update),
	}
}

func Unless

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

Unless skips the given hook only for the given operation.

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

Types

type BlogFunc

The BlogFunc type is an adapter to allow the use of ordinary function as Blog mutator.

func (BlogFunc) Mutate

Mutate calls f(ctx, m).

type CarFunc

The CarFunc type is an adapter to allow the use of ordinary function as Car mutator.

func (CarFunc) 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 ...fluentv2.Hook) Chain

NewChain creates a new chain of hooks.

func (Chain) Append

func (c Chain) Append(hooks ...fluentv2.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() fluentv2.Hook

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

type Condition

type Condition func(context.Context, fluentv2.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 fluentv2.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 ConversionFunc

type ConversionFunc func(context.Context, *fluentv2.ConversionMutation) (fluentv2.Value, error)

The ConversionFunc type is an adapter to allow the use of ordinary function as Conversion mutator.

func (ConversionFunc) Mutate

Mutate calls f(ctx, m).

type CustomTypeFunc

type CustomTypeFunc func(context.Context, *fluentv2.CustomTypeMutation) (fluentv2.Value, error)

The CustomTypeFunc type is an adapter to allow the use of ordinary function as CustomType mutator.

func (CustomTypeFunc) Mutate

Mutate calls f(ctx, m).

type GroupFunc

The GroupFunc type is an adapter to allow the use of ordinary function as Group mutator.

func (GroupFunc) Mutate

Mutate calls f(ctx, m).

type MediaFunc

The MediaFunc type is an adapter to allow the use of ordinary function as Media mutator.

func (MediaFunc) Mutate

Mutate calls f(ctx, m).

type PetFunc

The PetFunc type is an adapter to allow the use of ordinary function as Pet mutator.

func (PetFunc) Mutate

Mutate calls f(ctx, m).

type UserFunc

The UserFunc type is an adapter to allow the use of ordinary function as User mutator.

func (UserFunc) Mutate

Mutate calls f(ctx, m).

type ZooFunc

The ZooFunc type is an adapter to allow the use of ordinary function as Zoo mutator.

func (ZooFunc) Mutate

Mutate calls f(ctx, m).

Jump to

Keyboard shortcuts

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