iox

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: May 17, 2025 License: Apache-2.0 Imports: 4 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 ConcurrentMultipleBytes added in v0.0.10

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

ConcurrentMultipleBytes 是 MultipleBytes 的线程安全装饰器

func NewConcurrentMultipleBytes added in v0.0.10

func NewConcurrentMultipleBytes(sliceCount int) *ConcurrentMultipleBytes

NewConcurrentMultipleBytes 创建一个新的线程安全的 MultipleBytes 实例 sliceCount 参数用于预分配内部切片数组的容量

func (*ConcurrentMultipleBytes) Read added in v0.0.10

func (c *ConcurrentMultipleBytes) Read(p []byte) (n int, err error)

Read 实现 io.Reader 接口 从当前位置读取数据到 p 中,如果没有数据可读返回 io.EOF

func (*ConcurrentMultipleBytes) Reset added in v0.0.10

func (c *ConcurrentMultipleBytes) Reset()

Reset 重置读取位置到开始处

func (*ConcurrentMultipleBytes) Write added in v0.0.10

func (c *ConcurrentMultipleBytes) Write(p []byte) (n int, err error)

Write 实现 io.Writer 接口 将 p 中的数据写入到内部缓冲区

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)

type MultipleBytes added in v0.0.10

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

MultipleBytes 是一个实现了 io.Reader 和 io.Writer 接口的结构体 它可以安全地在多个 goroutine 之间共享

func NewMultipleBytes added in v0.0.10

func NewMultipleBytes(sliceCount int) *MultipleBytes

NewMultipleBytes 创建一个新的 MultipleBytes 实例 sliceCount 参数用于预分配内部切片数组的容量

func (*MultipleBytes) Read added in v0.0.10

func (m *MultipleBytes) Read(p []byte) (n int, err error)

Read 实现 io.Reader 接口 从当前位置读取数据到 p 中,如果没有数据可读返回 io.EOF

func (*MultipleBytes) Reset added in v0.0.10

func (m *MultipleBytes) Reset()

Reset 重置读取位置到开始处

func (*MultipleBytes) Write added in v0.0.10

func (m *MultipleBytes) Write(p []byte) (n int, err error)

Write 实现 io.Writer 接口 将 p 中的数据写入到内部缓冲区

Jump to

Keyboard shortcuts

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