hook

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2023 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Logger       zerolog.Logger
	Verification config.Policy
	// contains filtered or unexported fields
}

func NewHookConfig

func NewHookConfig() *Config

NewHookConfig returns a new Config.

func (*Config) Add

func (h *Config) Add(hookType Type, prio Priority, hookFunc FunctionType)

Add adds a hook with a priority to the hooks map.

func (*Config) Get

func (h *Config) Get(hookType Type) map[Priority]FunctionType

Get returns the hooks of a specific type.

func (*Config) Hooks

func (h *Config) Hooks() map[Type]map[Priority]FunctionType

Hooks returns the hooks.

func (*Config) Run

func (h *Config) Run(
	ctx context.Context,
	args map[string]interface{},
	hookType Type,
	verification config.Policy,
	opts ...grpc.CallOption,
) (map[string]interface{}, *gerr.GatewayDError)

Run runs the hooks of a specific type. The result of the previous hook is passed to the next hook as the argument, aka. chained. The context is passed to the hooks as well to allow them to cancel the execution. The args are passed to the first hook as the argument. The result of the first hook is passed to the second hook, and so on. The result of the last hook is eventually returned. The verification mode is used to determine how to handle errors. If the verification mode is set to Abort, the execution is aborted on the first error. If the verification mode is set to Remove, the hook is removed from the list of hooks on the first error. If the verification mode is set to Ignore, the error is ignored and the execution continues. If the verification mode is set to PassDown, the extra keys/values in the result are passed down to the next The verification mode is set to PassDown by default. The opts are passed to the hooks as well to allow them to use the grpc.CallOption.

type FunctionType

type FunctionType func(
	context.Context, *structpb.Struct, ...grpc.CallOption) (*structpb.Struct, error)

type Priority

type Priority uint

Priority is the priority of a hook. Smaller values are executed first (higher priority).

type Type

type Type string
const (
	// Run command hooks (cmd/run.go).
	OnConfigLoaded Type = "onConfigLoaded"
	OnNewLogger    Type = "onNewLogger"
	OnNewPool      Type = "onNewPool"
	OnNewProxy     Type = "onNewProxy"
	OnNewServer    Type = "onNewServer"
	OnSignal       Type = "onSignal"
	// Server hooks (network/server.go).
	OnRun               Type = "onRun"
	OnBooting           Type = "onBooting"
	OnBooted            Type = "onBooted"
	OnOpening           Type = "onOpening"
	OnOpened            Type = "onOpened"
	OnClosing           Type = "onClosing"
	OnClosed            Type = "onClosed"
	OnTraffic           Type = "onTraffic"
	OnTrafficFromClient Type = "onTrafficFromClient"
	OnTrafficToServer   Type = "onTrafficToServer"
	OnTrafficFromServer Type = "onTrafficFromServer"
	OnTrafficToClient   Type = "onTrafficToClient"
	OnShutdown          Type = "onShutdown"
	OnTick              Type = "onTick"
	// Pool hooks (network/pool.go).
	OnNewClient Type = "onNewClient"
)

Jump to

Keyboard shortcuts

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