gotools

package module
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: MIT Imports: 2 Imported by: 0

README

gotools

项目结构

  • func PickReaderPrefix(r io.Reader, l int) ([]byte, io.Reader, error): PickReaderPrefix 从reader中读取指定长度的数据,并返回读取的数据和新的reader

  • collections

    • type TTLMap struct: TTLMap 是一个带有过期时间的map
    • type List[T any] struct: List 是一个泛型实现的列表,但并非协程安全的
    • type SafeList[T any] struct: SafeList 是一个泛型实现的列表,是协程安全的
    • type SuperMap[K int | string, V any] struct: SuperMap 是一个泛型实现的协程安全的Map,提供多种实用的操作函数,如:过滤、更新、比较 等
  • stream

    • func Replace(reader io.Reader, writer io.Writer, old, new []byte) error : Replace 从reader中读取数据,替换old为new,并写入writer(流式处理,不会全部读到内存里)
    • func MaskKeywords(reader io.Reader, writer io.Writer, words [][]byte, mask []byte) error: MaskKeywords 从reader中读取数据,将words中的关键字替换为mask,并写入writer
    • func MaskBytes(byteArray []byte, keywords [][]byte, mask []byte) []byte: MaskBytes 将byteArray中的关键字替换为mask
  • strtools

    • ParseList(s string) []string: ParseList 解析字符串为字符串列表
  • tokenbucket

    • type TokenBucket struct: TokenBucket 是一个令牌桶,桶内自带锁,协程安全

使用示例

package main

import (
	"fmt"

	"github.com/moonlightwatch/gotools/collections"
)

func main() {
	list1 := collections.NewSafeList[string]()
	list2 := collections.NewSafeList[string]()

	list1.Add("a")
	list1.Add("b")
	list1.Add("c")

	list2.Add("c")
	list2.Add("d")

	diff := list1.Difference(list2).Elements()

	fmt.Println(diff)
}

上述代码输出: [a b]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PickReaderPrefix added in v0.1.3

func PickReaderPrefix(r io.Reader, l int) ([]byte, io.Reader, error)

PickReaderPrefix 从reader中读取指定长度的数据,并返回读取的数据和新的reader

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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