hook

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 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 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 GlobalSettingsFunc

type GlobalSettingsFunc func(context.Context, *lion.GlobalSettingsMutation) (lion.Value, error)

The GlobalSettingsFunc type is an adapter to allow the use of ordinary function as GlobalSettings mutator.

func (GlobalSettingsFunc) Mutate

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 MenusFunc func(context.Context, *lion.MenusMutation) (lion.Value, error)

The MenusFunc type is an adapter to allow the use of ordinary function as Menus mutator.

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

Mutate calls f(ctx, m).

type OAuth2ClientsFunc

type OAuth2ClientsFunc func(context.Context, *lion.OAuth2ClientsMutation) (lion.Value, error)

The OAuth2ClientsFunc type is an adapter to allow the use of ordinary function as OAuth2Clients mutator.

func (OAuth2ClientsFunc) Mutate

Mutate calls f(ctx, m).

type OAuth2CodesFunc

type OAuth2CodesFunc func(context.Context, *lion.OAuth2CodesMutation) (lion.Value, error)

The OAuth2CodesFunc type is an adapter to allow the use of ordinary function as OAuth2Codes mutator.

func (OAuth2CodesFunc) 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 PrincipalRolesFunc

type PrincipalRolesFunc func(context.Context, *lion.PrincipalRolesMutation) (lion.Value, error)

The PrincipalRolesFunc type is an adapter to allow the use of ordinary function as PrincipalRoles mutator.

func (PrincipalRolesFunc) Mutate

Mutate calls f(ctx, m).

type RoleMenusFunc

type RoleMenusFunc func(context.Context, *lion.RoleMenusMutation) (lion.Value, error)

The RoleMenusFunc type is an adapter to allow the use of ordinary function as RoleMenus mutator.

func (RoleMenusFunc) Mutate

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

Mutate calls f(ctx, m).

type RolePoliciesFunc

type RolePoliciesFunc func(context.Context, *lion.RolePoliciesMutation) (lion.Value, error)

The RolePoliciesFunc type is an adapter to allow the use of ordinary function as RolePolicies mutator.

func (RolePoliciesFunc) 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 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 UserMembershipsFunc

type UserMembershipsFunc func(context.Context, *lion.UserMembershipsMutation) (lion.Value, error)

The UserMembershipsFunc type is an adapter to allow the use of ordinary function as UserMemberships mutator.

func (UserMembershipsFunc) 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 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