validator

package
v3.12.3 Latest Latest
Warning

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

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

Documentation

Overview

Package validator implements a gRPC middleware that defines custom validators that are invoked when the service is called.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterAllowedFieldMaskPaths

func RegisterAllowedFieldMaskPaths(rpcFullMethod string, set bool, allPaths []string, allowedPaths ...string)

RegisterAllowedFieldMaskPaths registers the allowed field mask paths for an RPC. Note that all allowed paths and sub-paths must be registered. This function is not safe for concurrent use.

func StreamServerInterceptor

func StreamServerInterceptor() grpc.StreamServerInterceptor

StreamServerInterceptor returns a new streaming server interceptor that validates incoming messages if those incoming messages implement:

(A) ValidateContext(ctx context.Context) error
(B) Validate() error
(C) ValidateFields(...string) error

If a message implements both, then (A) should call (B).

Invalid messages will be rejected with the error returned from the validator, if that error is a TTN error, or with an `InvalidArgument` if it isn't.

The stage at which invalid messages will be rejected with `InvalidArgument` varies based on the type of the RPC. For `ServerStream` (1:m) requests, it will happen before reaching any userspace handlers. For `ClientStream` (n:1) or `BidiStream` (n:m) RPCs, the messages will be rejected on calls to `stream.Recv()`.

If the RPC's FullPath has a registered list of allowed field mask paths (see RegisterAllowedFieldMaskPaths) and the message implements GetFieldMask() types.FieldMask then the field mask paths are validated according to the registered list.

func UnaryServerInterceptor

func UnaryServerInterceptor() grpc.UnaryServerInterceptor

UnaryServerInterceptor returns a new unary server interceptor that validates incoming messages if those incoming messages implement:

(A) ValidateContext(ctx context.Context) error
(B) Validate() error
(C) ValidateFields(...string) error

If a message implements both, then (A) should call (B).

Invalid messages will be rejected with the error returned from the validator, if that error is a TTN error, or with an `InvalidArgument` if it isn't.

If the RPC's FullPath has a registered list of allowed field mask paths (see RegisterAllowedFieldMaskPaths) and the message implements GetFieldMask() types.FieldMask then the field mask paths are validated according to the registered list.

Types

This section is empty.

Jump to

Keyboard shortcuts

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