json_decode_tee

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JsonDecode

func JsonDecode[T any](rd io.Reader, dst *T) error

JsonDecode 解析JSON数据,同时在解析失败时保留原始数据 参数:

  • rd: 数据源,实现io.Reader接口
  • dst: 目标结构体指针,解析后的数据将存储在此

返回值:

  • error: 解析成功返回nil,失败返回JsonDecodeError包含原始数据

示例:

var user User
err := JsonDecode(response.Body, &user)
if err != nil {
    var jsonErr *JsonDecodeError
    if errors.As(err, &jsonErr) {
        log.Printf("Failed to parse: %s, raw data: %s", err, jsonErr.Raw.String())
    }
}

func ReadErrRaw

func ReadErrRaw(err error) []byte

Types

type JsonDecodeError

type JsonDecodeError struct {
	Err error
	Raw bytes.Buffer
}

JsonDecodeError json解析错误 包含原始数据

func (*JsonDecodeError) Error

func (e *JsonDecodeError) Error() string

func (*JsonDecodeError) Unwrap

func (e *JsonDecodeError) Unwrap() error

Unwrap 返回被包装的原始错误,用于errors.Is和errors.As

Jump to

Keyboard shortcuts

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