hook

package
v0.3.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 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) model.Hook

FixedError is a hook returning a fixed error.

func If

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

If executes the given hook under condition.

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

func On

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

On executes the given hook only for the given operation.

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

func Reject

func Reject(op model.Op) model.Hook

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

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

func Unless

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

Unless skips the given hook only for the given operation.

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

Types

type CatalogFunc

type CatalogFunc func(context.Context, *model.CatalogMutation) (model.Value, error)

The CatalogFunc type is an adapter to allow the use of ordinary function as Catalog mutator.

func (CatalogFunc) Mutate

func (f CatalogFunc) Mutate(ctx context.Context, m model.Mutation) (model.Value, error)

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 ...model.Hook) Chain

NewChain creates a new chain of hooks.

func (Chain) Append

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

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

type Condition

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

type ConnectorFunc func(context.Context, *model.ConnectorMutation) (model.Value, error)

The ConnectorFunc type is an adapter to allow the use of ordinary function as Connector mutator.

func (ConnectorFunc) Mutate

Mutate calls f(ctx, m).

type CostReportFunc

type CostReportFunc func(context.Context, *model.CostReportMutation) (model.Value, error)

The CostReportFunc type is an adapter to allow the use of ordinary function as CostReport mutator.

func (CostReportFunc) Mutate

Mutate calls f(ctx, m).

type DistributeLockFunc

type DistributeLockFunc func(context.Context, *model.DistributeLockMutation) (model.Value, error)

The DistributeLockFunc type is an adapter to allow the use of ordinary function as DistributeLock mutator.

func (DistributeLockFunc) Mutate

Mutate calls f(ctx, m).

type EnvironmentConnectorRelationshipFunc

type EnvironmentConnectorRelationshipFunc func(context.Context, *model.EnvironmentConnectorRelationshipMutation) (model.Value, error)

The EnvironmentConnectorRelationshipFunc type is an adapter to allow the use of ordinary function as EnvironmentConnectorRelationship mutator.

func (EnvironmentConnectorRelationshipFunc) Mutate

Mutate calls f(ctx, m).

type EnvironmentFunc

type EnvironmentFunc func(context.Context, *model.EnvironmentMutation) (model.Value, error)

The EnvironmentFunc type is an adapter to allow the use of ordinary function as Environment mutator.

func (EnvironmentFunc) Mutate

Mutate calls f(ctx, m).

type PerspectiveFunc

type PerspectiveFunc func(context.Context, *model.PerspectiveMutation) (model.Value, error)

The PerspectiveFunc type is an adapter to allow the use of ordinary function as Perspective mutator.

func (PerspectiveFunc) Mutate

Mutate calls f(ctx, m).

type ProjectFunc

type ProjectFunc func(context.Context, *model.ProjectMutation) (model.Value, error)

The ProjectFunc type is an adapter to allow the use of ordinary function as Project mutator.

func (ProjectFunc) Mutate

func (f ProjectFunc) Mutate(ctx context.Context, m model.Mutation) (model.Value, error)

Mutate calls f(ctx, m).

type RoleFunc

type RoleFunc func(context.Context, *model.RoleMutation) (model.Value, error)

The RoleFunc type is an adapter to allow the use of ordinary function as Role mutator.

func (RoleFunc) Mutate

func (f RoleFunc) Mutate(ctx context.Context, m model.Mutation) (model.Value, error)

Mutate calls f(ctx, m).

type ServiceFunc

type ServiceFunc func(context.Context, *model.ServiceMutation) (model.Value, error)

The ServiceFunc type is an adapter to allow the use of ordinary function as Service mutator.

func (ServiceFunc) Mutate

func (f ServiceFunc) Mutate(ctx context.Context, m model.Mutation) (model.Value, error)

Mutate calls f(ctx, m).

type ServiceRelationshipFunc

type ServiceRelationshipFunc func(context.Context, *model.ServiceRelationshipMutation) (model.Value, error)

The ServiceRelationshipFunc type is an adapter to allow the use of ordinary function as ServiceRelationship mutator.

func (ServiceRelationshipFunc) Mutate

Mutate calls f(ctx, m).

type ServiceResourceFunc

type ServiceResourceFunc func(context.Context, *model.ServiceResourceMutation) (model.Value, error)

The ServiceResourceFunc type is an adapter to allow the use of ordinary function as ServiceResource mutator.

func (ServiceResourceFunc) Mutate

Mutate calls f(ctx, m).

type ServiceResourceRelationshipFunc

type ServiceResourceRelationshipFunc func(context.Context, *model.ServiceResourceRelationshipMutation) (model.Value, error)

The ServiceResourceRelationshipFunc type is an adapter to allow the use of ordinary function as ServiceResourceRelationship mutator.

func (ServiceResourceRelationshipFunc) Mutate

Mutate calls f(ctx, m).

type ServiceRevisionFunc

type ServiceRevisionFunc func(context.Context, *model.ServiceRevisionMutation) (model.Value, error)

The ServiceRevisionFunc type is an adapter to allow the use of ordinary function as ServiceRevision mutator.

func (ServiceRevisionFunc) Mutate

Mutate calls f(ctx, m).

type SettingFunc

type SettingFunc func(context.Context, *model.SettingMutation) (model.Value, error)

The SettingFunc type is an adapter to allow the use of ordinary function as Setting mutator.

func (SettingFunc) Mutate

func (f SettingFunc) Mutate(ctx context.Context, m model.Mutation) (model.Value, error)

Mutate calls f(ctx, m).

type SubjectFunc

type SubjectFunc func(context.Context, *model.SubjectMutation) (model.Value, error)

The SubjectFunc type is an adapter to allow the use of ordinary function as Subject mutator.

func (SubjectFunc) Mutate

func (f SubjectFunc) Mutate(ctx context.Context, m model.Mutation) (model.Value, error)

Mutate calls f(ctx, m).

type SubjectRoleRelationshipFunc

type SubjectRoleRelationshipFunc func(context.Context, *model.SubjectRoleRelationshipMutation) (model.Value, error)

The SubjectRoleRelationshipFunc type is an adapter to allow the use of ordinary function as SubjectRoleRelationship mutator.

func (SubjectRoleRelationshipFunc) Mutate

Mutate calls f(ctx, m).

type TemplateFunc

type TemplateFunc func(context.Context, *model.TemplateMutation) (model.Value, error)

The TemplateFunc type is an adapter to allow the use of ordinary function as Template mutator.

func (TemplateFunc) Mutate

func (f TemplateFunc) Mutate(ctx context.Context, m model.Mutation) (model.Value, error)

Mutate calls f(ctx, m).

type TemplateVersionFunc

type TemplateVersionFunc func(context.Context, *model.TemplateVersionMutation) (model.Value, error)

The TemplateVersionFunc type is an adapter to allow the use of ordinary function as TemplateVersion mutator.

func (TemplateVersionFunc) Mutate

Mutate calls f(ctx, m).

type TokenFunc

type TokenFunc func(context.Context, *model.TokenMutation) (model.Value, error)

The TokenFunc type is an adapter to allow the use of ordinary function as Token mutator.

func (TokenFunc) Mutate

func (f TokenFunc) Mutate(ctx context.Context, m model.Mutation) (model.Value, error)

Mutate calls f(ctx, m).

type VariableFunc

type VariableFunc func(context.Context, *model.VariableMutation) (model.Value, error)

The VariableFunc type is an adapter to allow the use of ordinary function as Variable mutator.

func (VariableFunc) Mutate

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