utf8validator

package
v1.24.0-m2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidUTF8          = errors.New("invalid utf-8 in string field")
	ErrInvalidMessageSource = errors.New("invalid message source")
)
View Source
var Module = fx.Options(
	fx.Provide(utf8ValidatorProvider),
)

Functions

func Validate

func Validate(
	m proto.Message,
	source MessageSource,
	tags ...tag.Tag,
) error

Validate maybe validates one proto message, depending on dynamic config and random sampling. If validation fails, this may still return no error, depending on dynamic config. This deliberately does not return a serviceerror because the decision of which serviceerror to use is contextual. The caller should wrap it in the appropriate serviceerror.

Types

type MessageSource

type MessageSource int
const (
	SourceRPCRequest MessageSource = iota
	SourceRPCResponse
	SourcePersistence
)

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

A Validator validates utf-8 in string fields of proto messages. The proto library normally does this automatically, but we disable it for now as part of migration from gogoproto, which did not validate. Eventually we'll remove this and enable it normally.

func (*Validator) Intercept

func (v *Validator) Intercept(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error)

Intercept acts as grpc interceptor.

func (*Validator) Validate

func (v *Validator) Validate(
	m proto.Message,
	source MessageSource,
	tags ...tag.Tag,
) error

Validate maybe validates one proto message, depending on dynamic config and random sampling. If validation fails, this may still return no error, depending on dynamic config. This deliberately does not return a serviceerror because the decision of which serviceerror to use is contextual. The caller should wrap it in the appropriate serviceerror.

Jump to

Keyboard shortcuts

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