decoder

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package decoder provides decoders.

Index

Constants

View Source
const (
	// ContentTypeFormURL content-type header for url form decoder.
	ContentTypeFormURL = "application/x-www-form-urlencoded"
	// SplitSymbol array split symbol.
	SplitSymbol = ","
)
View Source
const (
	// ContentTypeJSON content-type header for json decoder.
	ContentTypeJSON = "application/json"
)
View Source
const (
	// ContentTypeMultipartFormData content-type header for multipart form-data decoder.
	ContentTypeMultipartFormData = "multipart/form-data"
)
View Source
const (
	// ContentTypeXML content-type header for xml decoder.
	ContentTypeXML = "application/xml"
)

Variables

This section is empty.

Functions

func WithContentType

func WithContentType[T contentTypeSetter](contentType string) func(T)

WithContentType sets content type.

func WithSkipFilled added in v1.7.1

func WithSkipFilled[T skipFilledSetter](skip bool) func(T)

WithSkipFilled sets skip filled.

Types

type FormURL

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

FormURL url form decoder.

func NewFormURL

func NewFormURL(opts ...FormURLOptionsFunc) *FormURL

NewFormURL returns new url form decoder.

func (*FormURL) ContentType

func (f *FormURL) ContentType() string

ContentType returns content-type header value.

func (*FormURL) Decode

func (f *FormURL) Decode(r *http.Request, ptr any) error

Decode decodes url form value from http request into ptr.

ptr must have a type of either struct or map.

func (*FormURL) EnableExperimentalFastStructFieldParser added in v1.7.0

func (f *FormURL) EnableExperimentalFastStructFieldParser()

EnableExperimentalFastStructFieldParser enables the use of experimental fast struct field parser.

type FormURLOptionsFunc

type FormURLOptionsFunc func(*FormURL)

FormURLOptionsFunc function for setting options.

func WithDisabledSplit

func WithDisabledSplit() FormURLOptionsFunc

WithDisabledSplit disables array splitting.

func WithSplitSymbol

func WithSplitSymbol(splitSymbol string) FormURLOptionsFunc

WithSplitSymbol sets array split symbol.

type JSON

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

JSON json decoder.

func NewJSON

func NewJSON(opts ...JSONOptionsFunc) *JSON

NewJSON returns new json decoder.

func (*JSON) ContentType

func (j *JSON) ContentType() string

ContentType returns content-type header value.

func (*JSON) Decode

func (j *JSON) Decode(r *http.Request, ptr any) error

Decode decodes request body into ptr.

type JSONOptionsFunc

type JSONOptionsFunc = func(*JSON)

JSONOptionsFunc function for setting xml options.

type MultipartFile

type MultipartFile struct {
	Key    string
	File   multipart.File
	Header *multipart.FileHeader
}

MultipartFile parsed multipart form-data file.

func (*MultipartFile) ContentType

func (f *MultipartFile) ContentType() string

ContentType returns content type of parsed file.

func (*MultipartFile) Copy

func (f *MultipartFile) Copy() (MultipartFile, error)

Copy returns copy of parsed file.

func (*MultipartFile) IsValid added in v1.7.1

func (f *MultipartFile) IsValid() bool

IsValid returns valid state of parsed file.

type MultipartFiles

type MultipartFiles []MultipartFile

MultipartFiles parsed multipart form-data files.

func (MultipartFiles) Close

func (mf MultipartFiles) Close() error

Close close all files.

type MultipartFormData

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

MultipartFormData multipart form-data decoder.

func NewMultipartFormData

func NewMultipartFormData(opts ...MultipartFormDataOptionsFunc) *MultipartFormData

NewMultipartFormData returns new multipart form-data decoder.

func (*MultipartFormData) ContentType

func (m *MultipartFormData) ContentType() string

ContentType returns content type of url form decoder.

func (*MultipartFormData) Decode

func (m *MultipartFormData) Decode(r *http.Request, ptr any) error

Decode decodes url form value from http request into ptr.

ptr must be pointer to a struct.

func (*MultipartFormData) EnableExperimentalFastStructFieldParser added in v1.7.0

func (m *MultipartFormData) EnableExperimentalFastStructFieldParser()

EnableExperimentalFastStructFieldParser enables the use of experimental fast struct field parser.

type MultipartFormDataOptionsFunc

type MultipartFormDataOptionsFunc = func(*MultipartFormData)

MultipartFormDataOptionsFunc function for setting options.

func WithMaxMemory

func WithMaxMemory(maxMemory int64) MultipartFormDataOptionsFunc

WithMaxMemory sets max memory.

type XML

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

XML xml decoder.

func NewXML

func NewXML(opts ...XMLOptionsFunc) *XML

NewXML returns new xml decoder.

func (*XML) ContentType

func (x *XML) ContentType() string

ContentType returns content-type header value.

func (*XML) Decode

func (x *XML) Decode(r *http.Request, ptr any) error

Decode decodes request body into ptr.

type XMLOptionsFunc

type XMLOptionsFunc = func(*XML)

XMLOptionsFunc function for setting xml options.

Jump to

Keyboard shortcuts

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