decoder

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 5 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 interface{}) error

DecodeJSONBody decodes a JSON request body. Call errors.Is(err, ErrBodyTooLarge) or errors.Is(err, ErrInvalidJSON). DecodeJSONBody 解码 JSON 请求体。 调用 errors.Is(err, ErrBodyTooLarge) 或 errors.Is(err, ErrInvalidJSON) 判断错误。

func DecodeJSONBodyWithOptions added in v0.2.1

func DecodeJSONBodyWithOptions(r *http.Request, out interface{}, opts JSONOptions) error

DecodeJSONBodyWithOptions decodes a JSON request body with options. Call errors.Is(err, ErrBodyTooLarge) or errors.Is(err, ErrInvalidJSON). DecodeJSONBodyWithOptions 按选项解码 JSON 请求体。 调用 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