hook

package
v0.3.9-beta.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 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) lion.Hook

FixedError is a hook returning a fixed error.

func If

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

If executes the given hook under condition.

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

func On

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

On executes the given hook only for the given operation.

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

func Reject

func Reject(op lion.Op) lion.Hook

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

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

func Unless

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

Unless skips the given hook only for the given operation.

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

Types

type AuthProvidersFunc

type AuthProvidersFunc func(context.Context, *lion.AuthProvidersMutation) (lion.Value, error)

The AuthProvidersFunc type is an adapter to allow the use of ordinary function as AuthProviders mutator.

func (AuthProvidersFunc) 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 ...lion.Hook) Chain

NewChain creates a new chain of hooks.

func (Chain) Append

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

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

type Condition

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

type CredentialsFunc func(context.Context, *lion.CredentialsMutation) (lion.Value, error)

The CredentialsFunc type is an adapter to allow the use of ordinary function as Credentials mutator.

func (CredentialsFunc) Mutate

Mutate calls f(ctx, m).

type DemoFunc

type DemoFunc func(context.Context, *lion.DemoMutation) (lion.Value, error)

The DemoFunc type is an adapter to allow the use of ordinary function as Demo mutator.

func (DemoFunc) Mutate

func (f DemoFunc) Mutate(ctx context.Context, m lion.Mutation) (lion.Value, error)

Mutate calls f(ctx, m).

type DepartmentRolesFunc

type DepartmentRolesFunc func(context.Context, *lion.DepartmentRolesMutation) (lion.Value, error)

The DepartmentRolesFunc type is an adapter to allow the use of ordinary function as DepartmentRoles mutator.

func (DepartmentRolesFunc) Mutate

Mutate calls f(ctx, m).

type DepartmentsFunc

type DepartmentsFunc func(context.Context, *lion.DepartmentsMutation) (lion.Value, error)

The DepartmentsFunc type is an adapter to allow the use of ordinary function as Departments mutator.

func (DepartmentsFunc) Mutate

Mutate calls f(ctx, m).

type GroupRolesFunc

type GroupRolesFunc func(context.Context, *lion.GroupRolesMutation) (lion.Value, error)

The GroupRolesFunc type is an adapter to allow the use of ordinary function as GroupRoles mutator.

func (GroupRolesFunc) Mutate

func (f GroupRolesFunc) Mutate(ctx context.Context, m lion.Mutation) (lion.Value, error)

Mutate calls f(ctx, m).

type GroupsFunc

type GroupsFunc func(context.Context, *lion.GroupsMutation) (lion.Value, error)

The GroupsFunc type is an adapter to allow the use of ordinary function as Groups mutator.

func (GroupsFunc) Mutate

func (f GroupsFunc) Mutate(ctx context.Context, m lion.Mutation) (lion.Value, error)

Mutate calls f(ctx, m).

type PermissionsFunc

type PermissionsFunc func(context.Context, *lion.PermissionsMutation) (lion.Value, error)

The PermissionsFunc type is an adapter to allow the use of ordinary function as Permissions mutator.

func (PermissionsFunc) Mutate

Mutate calls f(ctx, m).

type PoliciesFunc

type PoliciesFunc func(context.Context, *lion.PoliciesMutation) (lion.Value, error)

The PoliciesFunc type is an adapter to allow the use of ordinary function as Policies mutator.

func (PoliciesFunc) Mutate

func (f PoliciesFunc) Mutate(ctx context.Context, m lion.Mutation) (lion.Value, error)

Mutate calls f(ctx, m).

type ResourcesFunc

type ResourcesFunc func(context.Context, *lion.ResourcesMutation) (lion.Value, error)

The ResourcesFunc type is an adapter to allow the use of ordinary function as Resources mutator.

func (ResourcesFunc) Mutate

func (f ResourcesFunc) Mutate(ctx context.Context, m lion.Mutation) (lion.Value, error)

Mutate calls f(ctx, m).

type RolePermissionsFunc

type RolePermissionsFunc func(context.Context, *lion.RolePermissionsMutation) (lion.Value, error)

The RolePermissionsFunc type is an adapter to allow the use of ordinary function as RolePermissions mutator.

func (RolePermissionsFunc) Mutate

Mutate calls f(ctx, m).

type RolesFunc

type RolesFunc func(context.Context, *lion.RolesMutation) (lion.Value, error)

The RolesFunc type is an adapter to allow the use of ordinary function as Roles mutator.

func (RolesFunc) Mutate

func (f RolesFunc) Mutate(ctx context.Context, m lion.Mutation) (lion.Value, error)

Mutate calls f(ctx, m).

type UserDepartmentsFunc

type UserDepartmentsFunc func(context.Context, *lion.UserDepartmentsMutation) (lion.Value, error)

The UserDepartmentsFunc type is an adapter to allow the use of ordinary function as UserDepartments mutator.

func (UserDepartmentsFunc) Mutate

Mutate calls f(ctx, m).

type UserGroupsFunc

type UserGroupsFunc func(context.Context, *lion.UserGroupsMutation) (lion.Value, error)

The UserGroupsFunc type is an adapter to allow the use of ordinary function as UserGroups mutator.

func (UserGroupsFunc) Mutate

func (f UserGroupsFunc) Mutate(ctx context.Context, m lion.Mutation) (lion.Value, error)

Mutate calls f(ctx, m).

type UserIdentitiesFunc

type UserIdentitiesFunc func(context.Context, *lion.UserIdentitiesMutation) (lion.Value, error)

The UserIdentitiesFunc type is an adapter to allow the use of ordinary function as UserIdentities mutator.

func (UserIdentitiesFunc) Mutate

Mutate calls f(ctx, m).

type UserProfilesFunc

type UserProfilesFunc func(context.Context, *lion.UserProfilesMutation) (lion.Value, error)

The UserProfilesFunc type is an adapter to allow the use of ordinary function as UserProfiles mutator.

func (UserProfilesFunc) Mutate

Mutate calls f(ctx, m).

type UserRolesFunc

type UserRolesFunc func(context.Context, *lion.UserRolesMutation) (lion.Value, error)

The UserRolesFunc type is an adapter to allow the use of ordinary function as UserRoles mutator.

func (UserRolesFunc) Mutate

func (f UserRolesFunc) Mutate(ctx context.Context, m lion.Mutation) (lion.Value, error)

Mutate calls f(ctx, m).

type UsersFunc

type UsersFunc func(context.Context, *lion.UsersMutation) (lion.Value, error)

The UsersFunc type is an adapter to allow the use of ordinary function as Users mutator.

func (UsersFunc) Mutate

func (f UsersFunc) Mutate(ctx context.Context, m lion.Mutation) (lion.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