grpc_playground_validator

package
v0.0.0-...-4d6aaaa Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

*

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContextWithLocale

func NewContextWithLocale(parent context.Context, value string) context.Context

NewContextWithLocale creates new context with locale

func UnaryServerInterceptor

func UnaryServerInterceptor(v *Validator) grpc.UnaryServerInterceptor

UnaryServerInterceptor returns validator server interceptor for every request. If the request cannot be validated, the client gets the error with codes.FailedCondition If the request is nil, then this interceptor does nothing. If multiple languages are supported and should be different from each request, then the context which is generated by NewContextWithLocale should be passed before this interceptor.

Types

type Validator

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

Validator validates struct with translated messages

func NewValidator

func NewValidator(vOpts ...ValidatorOptions) (*Validator, error)

NewValidator returns Validator

func (*Validator) RegisterValidationCtx

func (v *Validator) RegisterValidationCtx(tag string, fn validatorv9.FuncCtx) error

RegisterValidationCtx applies go-playground/validator.v9/Validate.RegisterValidationCtx

func (*Validator) ValidateGRPCRequest

func (v *Validator) ValidateGRPCRequest(ctx context.Context, req interface{}) (*status.Status, error)

ValidateGRPCRequest validates the request and returns the grpc status if it's error

type ValidatorOptions

type ValidatorOptions func(o *validatorOptions)

ValidatorOptions is the options for NewValidator function

func WithRegisterDefaultTranslationFunc

func WithRegisterDefaultTranslationFunc(localePrefix string, registerDefaultTranslationFunc registerTranslationFunc) ValidatorOptions

WithTranslators returns the option to set translation functions for locales matching with localePrefix

func WithTranslators

func WithTranslators(fallbackTranslator locales.Translator, localeTranslators ...locales.Translator) ValidatorOptions

WithTranslators returns the option for locale translators

Jump to

Keyboard shortcuts

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