iox

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 2 Imported by: 2 modules, 1 package

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JSONReader

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

func NewJSONReader

func NewJSONReader(val any) *JSONReader

NewJSONReader 用于解决将一个结构体序列化为 JSON 之后,再封装为 io.Reader 的场景。 该实现没有做任何输入检查。 也就是你需要自己确保 val 是一个可以被 json 正确处理的东西。 非线程安全。 如果你传入的是 nil,那么读到的结果应该是 null。务必小心。

Example
package main

import (
	"fmt"
	"net/http"

	"github.com/ecodeclub/ekit/iox"
)

func main() {
	val := iox.NewJSONReader(User{Name: "Tom"})
	_, err := http.NewRequest(http.MethodPost, "/hello", val)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	fmt.Println("OK")
}

type User struct {
	Name string `json:"name"`
}

func (*JSONReader) Read

func (j *JSONReader) Read(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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