Categorygithub.com/itnxs/batch-reader
modulepackage
1.1.0
Repository: https://github.com/itnxs/batch-reader.git
Documentation: pkg.go.dev

# README

batch-reader

文件批量读取

文件批量读取

  1. 批量读取文件,主要用于大日志逐行度取,支持读取文本文件和GZ文件
  2. 支持文件读取行数记录,用于继续读取,

文件状态

name: /example/status.yaml
fileLine: {}
done:
- /example/data.txt

使用方法

package main

import (
	"context"
	"fmt"
	"os"
	"os/signal"
	"syscall"

	"github.com/itnxs/batch-reader"
	"github.com/sirupsen/logrus"
)

func main() {
	// 读取目录文件
	files, err := batch_reader.LoadFiles("./")
	if err != nil {
		panic(err)
	}

	ctx, cancel := context.WithCancel(context.Background())
	go watch(cancel)

	// 读取文件内容
	r := batch_reader.NewFileBatchReader(2)
	err = r.Run(ctx, files, func(ctx context.Context, data []byte) error {
		fmt.Println(string(data))
		return nil
	})

	if err != nil {
		panic(err)
	}
}

func watch(cancel context.CancelFunc) {
	sign := make(chan os.Signal, 1)
	signal.Notify(sign, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGSTOP)
	s := <-sign
	logrus.WithField("signal", s.String()).Info("receive signal")
	cancel()
}

# Packages

No description provided by the author

# Functions

CheckFiles 检查文件列表 files 文件列表.
Exist 是否存在 name 文件或则目录名称.
LoadFiles 获取文件 source 源目录名称 all 是否获取所有子文件夹下的.
NewFileBatchReader 新建一个文件批量读取 process 携程数量 statusName 状态存储地址.
ReadLine 按行读取内容 ctx 上下文 source 文件地址 line 开始如取的行号 handle 读取后回调函数.

# Structs

FileBatchReader 文件批量读取.

# Type aliases

Handler 处理 ctx 上下文 data 行数据.