decoder

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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