validate

package
v0.83.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package validate provides a simple way to validate and parse data from HTTP requests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidationError

func IsValidationError(err error) bool

func JSONBodyInto

func JSONBodyInto(r *http.Request, destStructPtr any) error

JSONBodyInto decodes an HTTP request body into a struct and validates it.

func JSONBytesInto

func JSONBytesInto(data []byte, destStructPtr any) error

JSONBytesInto decodes a byte slice containing JSON data into a struct and validates it.

func JSONStrInto

func JSONStrInto(data string, destStructPtr any) error

JSONStrInto decodes a string containing JSON data into a struct and validates it.

func URLSearchParamsInto

func URLSearchParamsInto(r *http.Request, destStructPtr any) error

URLSearchParamsInto parses the URL parameters of an HTTP request into a struct and validates it.

Types

type AnyChecker

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

func Any

func Any(label string, anything any) *AnyChecker

func (*AnyChecker) Email

func (c *AnyChecker) Email() *AnyChecker

func (*AnyChecker) EndsWith

func (c *AnyChecker) EndsWith(suffix string) *AnyChecker

func (*AnyChecker) Error

func (c *AnyChecker) Error() error

func (*AnyChecker) If

func (c *AnyChecker) If(condition bool, f func(*AnyChecker) *AnyChecker) *AnyChecker

func (*AnyChecker) In

func (c *AnyChecker) In(permittedValuesSlice any) *AnyChecker

In validates that the value is in the permitted values slice

func (*AnyChecker) Max

func (c *AnyChecker) Max(max float64) *AnyChecker

func (*AnyChecker) Min

func (c *AnyChecker) Min(min float64) *AnyChecker

func (*AnyChecker) NotIn

func (c *AnyChecker) NotIn(prohibitedValuesSlice any) *AnyChecker

NotIn validates that the value is not in the prohibited values slice

func (*AnyChecker) Optional

func (c *AnyChecker) Optional() *AnyChecker

func (*AnyChecker) PermittedChars

func (c *AnyChecker) PermittedChars(allowedChars string) *AnyChecker

func (*AnyChecker) RangeExclusive

func (c *AnyChecker) RangeExclusive(min, max float64) *AnyChecker

func (*AnyChecker) RangeInclusive

func (c *AnyChecker) RangeInclusive(min, max float64) *AnyChecker

func (*AnyChecker) Regex

func (c *AnyChecker) Regex(regex *regexp.Regexp) *AnyChecker

func (*AnyChecker) Required

func (c *AnyChecker) Required() *AnyChecker

func (*AnyChecker) StartsWith

func (c *AnyChecker) StartsWith(prefix string) *AnyChecker

func (*AnyChecker) URL

func (c *AnyChecker) URL() *AnyChecker

type ObjectChecker

type ObjectChecker struct {
	AnyChecker
	ChildCheckers []*AnyChecker
}

func Object

func Object(object any) *ObjectChecker

func (*ObjectChecker) Error

func (oc *ObjectChecker) Error() error

func (*ObjectChecker) MutuallyExclusive

func (oc *ObjectChecker) MutuallyExclusive(label string, fields ...string) *ObjectChecker

func (*ObjectChecker) MutuallyRequired

func (oc *ObjectChecker) MutuallyRequired(label string, fields ...string) *ObjectChecker

func (*ObjectChecker) Optional

func (oc *ObjectChecker) Optional(field string) *AnyChecker

func (*ObjectChecker) Required

func (oc *ObjectChecker) Required(field string) *AnyChecker

type ValidationError

type ValidationError struct{ Err error }

func (*ValidationError) Error

func (e *ValidationError) Error() string

func (*ValidationError) Unwrap

func (e *ValidationError) Unwrap() error

type Validator

type Validator interface{ Validate() error }

Jump to

Keyboard shortcuts

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