proto_validate_reflect

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: MIT Imports: 12 Imported by: 0

README

Proto Validate Reflect

GitHub License

Proto Validate Reflect is a Go library that offers dynamic message validation and reflection capabilities for Protocol Buffers (protobuf) messages. This library is designed to provide similar functionality to protoc-go-validate but focuses on dynamic messages, enabling you to work with protobuf messages without the need for statically generated Go code.

Table of Contents

Installation

To use Proto Validate Reflect in your Go project, you can simply use go get:

go get github.com/protoconf/proto-validate-reflect

Usage

Proto Validate Reflect allows you to perform dynamic validation and reflection on protobuf messages in Go.

Features

  • Dynamic message creation and manipulation.
  • Dynamic message validation based on protobuf message definitions.
  • Reflection capabilities for reading field values dynamically.
  • Compatibility with protoc-go-validate validation rules.
  • Custom validation rules and error handling.

Examples

For detailed usage examples and scenarios, please refer to the examples directory in this repository. You can find examples for:

  • Dynamic message creation and manipulation.
  • Dynamic message validation.
  • Reflection and field retrieval.
  • Custom validation rules.

Contributing

Contributions to Proto Validate Reflect are welcome! If you have ideas, bug reports, or want to contribute code or documentation, please check our Contribution Guidelines for details on how to get involved.

License

Proto Validate Reflect is open-source software licensed under the MIT License. Feel free to use and distribute it as you see fit, subject to the terms of the license.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorConst                        = errors.New("value does not match the const rule")
	ErrorLt                           = errors.New("value is not less than the specified value")
	ErrorLte                          = errors.New("value is not less than or equal to the specified value")
	ErrorGt                           = errors.New("value is not greater than the specified value")
	ErrorGte                          = errors.New("value is not greater than or equal to the specified value")
	ErrorLen                          = errors.New("value does not match the specified length")
	ErrorMinLen                       = errors.New("value is shorter than the minimum length")
	ErrorMaxLen                       = errors.New("value is longer than the maximum length")
	ErrorLenBytes                     = errors.New("byte length does not match the specified length")
	ErrorMinBytes                     = errors.New("byte length is less than the minimum specified")
	ErrorMaxBytes                     = errors.New("byte length exceeds the maximum specified")
	ErrorPattern                      = errors.New("value does not match the specified pattern")
	ErrorPrefix                       = errors.New("value does not have the specified prefix")
	ErrorSuffix                       = errors.New("value does not have the specified suffix")
	ErrorContains                     = errors.New("value does not contain the specified substring")
	ErrorNotContains                  = errors.New("value contains a prohibited substring")
	ErrorIn                           = errors.New("value is not in the specified set")
	ErrorNotIn                        = errors.New("value is in the not_in set")
	ErrorInvalid                      = errors.New("value is not valid")
	ErrorInvalidEmail                 = errors.New("value is not a valid email address")
	ErrorHostnameTooLong              = errors.New("hostname cannot exceed 253 characters")
	ErrorHostnameInvalidPart          = errors.New("hostname part must be non-empty and cannot exceed 63 characters")
	ErrorHostnamePartBeginWithHyphens = errors.New("hostname parts cannot begin with hyphens")
	ErrorHostnamePartEndsWithHyphens  = errors.New("hostname parts cannot end with hyphens")
	ErrorInvalidIp                    = errors.New("value is not a valid ip address")
	ErrorInvalidIpv4                  = errors.New("value is not a valid ipv4 address")
	ErrorInvalidIpv6                  = errors.New("value is not a valid ipv6 address")
	ErrorInvalidUri                   = errors.New("value is not a valid uri")
)

Functions

func Validate

func Validate(msg proto.Message) (bool, error)

func ValidateDouble

func ValidateDouble(value protoreflect.Value, rules *validate.DoubleRules) (bool, []error)

func ValidateDynamic

func ValidateDynamic(m *dynamicpb.Message) (bool, error)

func ValidateFloat

func ValidateFloat(value protoreflect.Value, rules *validate.FloatRules) (bool, []error)

func ValidateInt32

func ValidateInt32(value protoreflect.Value, rules *validate.Int32Rules) (bool, []error)

func ValidateInt64

func ValidateInt64(value protoreflect.Value, rules *validate.Int64Rules) (bool, []error)

func ValidateString

func ValidateString(value protoreflect.Value, rules *validate.StringRules) (bool, []error)

func ValidateUInt32

func ValidateUInt32(value protoreflect.Value, rules *validate.UInt32Rules) (bool, []error)

func ValidateUInt64

func ValidateUInt64(value protoreflect.Value, rules *validate.UInt64Rules) (bool, []error)

Types

type ValidateError

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

func (*ValidateError) Err

func (v *ValidateError) Err() error

func (*ValidateError) Error

func (v *ValidateError) Error() string

func (*ValidateError) Func

func (v *ValidateError) Func(name protoreflect.Name, f func() (bool, []error))

func (*ValidateError) Ok

func (v *ValidateError) Ok() bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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