grpchook

package
v0.1.26 Latest Latest
Warning

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

Go to latest
Published: May 26, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StreamNotificationInterceptor

func StreamNotificationInterceptor(recipients []notification.Sender, configs ...EndpointConfig) grpc.StreamServerInterceptor

The hook for streaming endpoints Assembles all endpoint configurations to one EndpointConfig and returns the hook function

func UnaryNotificationInterceptor

func UnaryNotificationInterceptor(recipients []notification.Sender, configs ...EndpointConfig) grpc.UnaryServerInterceptor

The hook for unary endpoints Assembles all endpoint configurations to one EndpointConfig and returns the hook function

Types

type Config

type Config struct {
	CustomShouldNotify ShouldNotifyForErrFunc
	SkipErrors         bool
	NotifyOnSuccess    bool
	ErrorCodes         []codes.Code
}

func (Config) ShouldNotifyForErr

func (c Config) ShouldNotifyForErr(ctx context.Context, err error) bool

ShouldNotify determines whether a notification should be sent for the provided error. The default behaviour can be overridden by setting a custom decision function with UseShouldNotifyForErrFunc(ShouldNotify).

type EndpointConfig

type EndpointConfig map[string]Config

func NewEndpointConfig

func NewEndpointConfig(funcName string, opts ...EndpointOption) EndpointConfig

The default options for an endpoint is * Send notifications on error only * Send notification on all error codes

type EndpointOption

type EndpointOption func(*Config)

func DoNotifyOnSuccess

func DoNotifyOnSuccess() EndpointOption

Set if a message notification should be sent if the request was handled successfully.

func DoSkipErrors

func DoSkipErrors() EndpointOption

Set to skip message notifications when a gRPC error occurs.

func NotifyOnlyOn

func NotifyOnlyOn(codes []codes.Code) EndpointOption

If this is set a slack notification will only be sent if any of these gRPC errors occurs. If this is not set a slack message will be sent on any gRPC error that occurs.

func UseShouldNotifyForErrFunc

func UseShouldNotifyForErrFunc(f ShouldNotifyForErrFunc) EndpointOption

UseShouldNotifyForErrFunc will use the provided function to determine whether a a slack notification should be sent for a given error.

type ShouldNotifyForErrFunc

type ShouldNotifyForErrFunc func(ctx context.Context, respError error) bool

ShouldNotifyFunc determines whether a notification should happen for a given error.

Jump to

Keyboard shortcuts

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