request

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

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

Go to latest
Published: Feb 18, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ParseError

type ParseError struct {
	Msg     string             `json:"message"`
	ErrCode response.ErrorCode `json:"code"`
	ErrData interface{}        `json:"data"`
}

ParseError struct defines the structure of the JSON parsing error

func (*ParseError) Code

func (p *ParseError) Code() response.ErrorCode

func (*ParseError) Data

func (p *ParseError) Data() interface{}

func (*ParseError) Message

func (p *ParseError) Message() string

type Reader

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

Reader has functions to read, parse nad validate request data

func NewReader

func NewReader(log *zap.Logger, jw *response.JSONWriter, validator *validator.Validator) *Reader

NewReader returns a new instance of Reader

func (*Reader) HandleParseError

func (read *Reader) HandleParseError(err error) *ParseError

HandleParseError checks the type of the error in request parsing and writes an appropriate response

func (*Reader) ReadJSONAndValidate

func (read *Reader) ReadJSONAndValidate(w http.ResponseWriter, r *http.Request, v interface{}) bool

ReadJSONAndValidate reads a json request body into the given struct and the validates the struct data

func (*Reader) ReadJSONRequest

func (read *Reader) ReadJSONRequest(r *http.Request, v interface{}) error

ReadJSONRequest reads a json request body into the given struct

type ValidationError

type ValidationError struct {
	ErrData []string `json:"data"`
}

ValidationError struct defines the structure of the Validation errors

func (*ValidationError) Code

func (*ValidationError) Data

func (v *ValidationError) Data() interface{}

func (*ValidationError) Message

func (v *ValidationError) Message() string

Jump to

Keyboard shortcuts

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