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 重置读取位置到开始处
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"`
}
Output:
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 参数用于预分配内部切片数组的容量