decoder

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBodyTooLarge = errors.New("body too large")
View Source
var ErrInvalidJSON = errors.New("invalid json")

Functions

func DecodeJSONBody

func DecodeJSONBody(r *http.Request, out any) error

DecodeJSONBody decodes a JSON request body. It rejects duplicate names and invalid UTF-8 and matches struct fields case-sensitively. Call errors.Is(err, ErrBodyTooLarge) or errors.Is(err, ErrInvalidJSON). DecodeJSONBody 解码 JSON 请求体。 它拒绝重复字段名和无效 UTF-8,并区分大小写匹配结构体字段。 调用 errors.Is(err, ErrBodyTooLarge) 或 errors.Is(err, ErrInvalidJSON) 判断错误。

func DecodeJSONBodyWithOptions added in v0.2.1

func DecodeJSONBodyWithOptions(r *http.Request, out any, opts JSONOptions) error

DecodeJSONBodyWithOptions decodes a JSON request body with options. It rejects duplicate names and invalid UTF-8 and matches struct fields case-sensitively. Call errors.Is(err, ErrBodyTooLarge) or errors.Is(err, ErrInvalidJSON). DecodeJSONBodyWithOptions 按选项解码 JSON 请求体。 它拒绝重复字段名和无效 UTF-8,并区分大小写匹配结构体字段。 调用 errors.Is(err, ErrBodyTooLarge) 或 errors.Is(err, ErrInvalidJSON) 判断错误。

Types

type JSONOptions added in v0.2.1

type JSONOptions struct {
	// DisallowUnknownFields rejects object fields that are not present in the target struct.
	// DisallowUnknownFields 拒绝目标结构体中不存在的对象字段。
	DisallowUnknownFields bool
}

JSONOptions configures DecodeJSONBodyWithOptions. Zero value preserves DecodeJSONBody behavior. JSONOptions 配置 DecodeJSONBodyWithOptions。 零值保持 DecodeJSONBody 行为。

Jump to

Keyboard shortcuts

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