validate

package
v0.0.52 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2024 License: BSD-3-Clause Imports: 8 Imported by: 2

Documentation

Overview

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

Index

Constants

View Source
const ValidationErrorPrefix = "validation error: "

Variables

This section is empty.

Functions

func IsValidationError added in v0.0.42

func IsValidationError(err error) bool

IsValidationError returns true if the error is a validation error.

Types

type Validate

type Validate struct {
	Instance *validator.Validate
}

Validate is a wrapper around the go-playground/validator package. It provides methods for validating and parsing data from HTTP requests.

func New added in v0.0.49

func New() *Validate

New creates a new Validate instance.

func (Validate) JSONBodyInto added in v0.0.34

func (v Validate) JSONBodyInto(body io.ReadCloser, destStructPtr any) error

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

func (Validate) JSONBytesInto added in v0.0.34

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

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

func (Validate) JSONStrInto added in v0.0.34

func (v Validate) JSONStrInto(data string, destStructPtr any) error

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

func (Validate) URLSearchParamsInto added in v0.0.34

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

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

func (Validate) UnmarshalFromBytes deprecated added in v0.0.17

func (v Validate) UnmarshalFromBytes(data []byte, destStructPtr any) error

Deprecated: UnmarshalFromBytes is deprecated. Use JSONBytesInto instead.

func (Validate) UnmarshalFromRequest deprecated

func (v Validate) UnmarshalFromRequest(r *http.Request, destStructPtr any) error

Deprecated: UnmarshalFromRequest is deprecated. Use `v.JSONBodyInto(r.Body, dest)` instead.

func (Validate) UnmarshalFromResponse deprecated added in v0.0.9

func (v Validate) UnmarshalFromResponse(r *http.Response, destStructPtr any) error

Deprecated: UnmarshalFromResponse is deprecated. Use `v.JSONBodyInto(r.Body, dest)` instead.

func (Validate) UnmarshalFromString deprecated

func (v Validate) UnmarshalFromString(data string, destStructPtr any) error

Deprecated: UnmarshalFromString is deprecated. Use JSONStrInto instead.

Jump to

Keyboard shortcuts

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