{"modulePath":"github.com/mrbtec/logkit","version":"v0.0.0-20250326130357-27107f468957","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package reader\n\n## Constants\n\n```go\nconst (\n\tDoneFileName = \"file.done\"\n\n\tFtSaveLogPath = \"ft_log\" // ft log 在 meta 中的文件夹名字\n)\n```\n\n```go\nconst (\n\tDefautFileRetention = 7\n\n\tModeMetrics = \"metrics\"\n)\n```\n\n## Variables\n\n```go\nvar ErrFileNotDir = errors.New(\"file is not directory\")\n```\n\n```go\nvar ErrFileNotRegular = errors.New(\"file is not regular\")\n```\n\n```go\nvar ErrMetaFileRead = errors.New(\"cannot read meta file\")\n```\n\n```go\nvar ErrNoFileChosen = errors.New(\"no files found\")\n```\n\n```go\nvar ErrStopped = errors.New(\"runner stopped\")\n```\n\n```go\nvar WaitNoSuchFile = 100 * time.Millisecond\n```\n\n## Functions\n\n```go\nfunc AndCondition(f1, f2 func(os.FileInfo) bool) func(os.FileInfo) bool\n```\n\n```go\nfunc CompressedFile(path string) bool\n```\n\n```go\nfunc GetLogPathAbs(conf conf.MapConf) (logpath, oldLogPath string, err error)\n```\n\n```go\nfunc GetMaxFile(logdir string, condition func(os.FileInfo) bool, gte func(f1, f2 os.FileInfo) bool) (chosen os.FileInfo, err error)\n```\nGetMaxFile 在指定的限制条件condition下，根据比较函数gte 选择最大的os.FileInfo condition 文件必须满足的条件 gte f1 \u003e= f2 则返回true\n\n```go\nfunc GetMetaOption(conf conf.MapConf) (string, string, string, error)\n```\n\n```go\nfunc GetMinFile(logdir string, condition func(os.FileInfo) bool, gte func(f1, f2 os.FileInfo) bool) (os.FileInfo, error)\n```\nGetMinFile 于getMaxFile 相反，返回最小的文件\n\n```go\nfunc HeadPatternMode(mode string, v interface{}) (reg *regexp.Regexp, err error)\n```\n\n```go\nfunc IgnoreFileSuffixes(file string, suffixes []string) bool\n```\nIgnoreFileSuffixes return true if file has suffix of one of the suffixes\n\n```go\nfunc IgnoreHidden(file string, ignoreHidden bool) bool\n```\nIgnoreHidden return ture if file has dot(.) which presents ignore files in \\*nix system\n\n```go\nfunc InRunTime(hour, minute int, runTime RunTime) bool\n```\n\n```go\nfunc JoinFileInode(filename, inode string) string\n```\n\n```go\nfunc NoCondition(f os.FileInfo) bool\n```\nNoCondition 无限制条件\n\n```go\nfunc NotCondition(f1 func(os.FileInfo) bool) func(os.FileInfo) bool\n```\n\n```go\nfunc OrCondition(f1, f2 func(os.FileInfo) bool) func(os.FileInfo) bool\n```\n\n```go\nfunc ParseLoopDuration(cronSched string) (dur time.Duration, err error)\n```\n\n```go\nfunc ParseNumber(str string) (number int, err error)\n```\n\n```go\nfunc ParseTime(timeStr string) (hour, minute int, err error)\n```\n\n```go\nfunc RegisterConstructor(typ string, c Constructor)\n```\nRegisterConstructor adds a new constructor for a given type of reader.\n\n```go\nfunc SetMetaPath(conf conf.MapConf, runnerName, metaDir string)\n```\n\n```go\nfunc ValidFileRegex(file, validFilePattern string) bool\n```\nValidFileRegex return true if file matches with validFilePattern\n\n## Types\n\n```go\ntype Constructor func(*Meta, conf.MapConf) (Reader, error)\n```\n\n```go\ntype DaemonReader interface {\n\t// Start 用于非阻塞的启动读取器对应的守护线程，需要读取器自行负责其生命周期\n\tStart() error\n}\n```\nDaemonReader 代表了一个需要守护线程的读取器\n\n```go\ntype DataReader interface {\n\t// ReadData 用于读取一条数据以及数据的实际读取字节\n\tReadData() (Data, int64, error)\n}\n```\nDataReader 代表了一个可直接读取内存数据结构的读取器\n\n```go\ntype FileReader interface {\n\tName() string\n\tSource() string\n\tRead(p []byte) (n int, err error)\n\tClose() error\n\tSyncMeta() error\n}\n```\nFileReader reader 接口方法\n\n```go\ntype LagReader interface {\n\tLag() (*LagInfo, error)\n}\n```\n获取数据lag的接口\n\n```go\ntype Meta struct {\n\tDir string // 记录文件处理进度的路径\n\n\tDoneFilePath string // 记录扫描过文件记录的文件\n\n\tTagFile string //记录tag文件路径的标签名称\n\n\tReadlimit int    //读取磁盘限速单位 MB/s\n\tDelimiter string //文件换行符\n\n\tRunnerName string\n\n\tLastKey string // 记录从s3 最近一次拉取的文件\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewMeta(metadir, filedonedir, logpath, mode, tagfile string, donefileRetention int) (m *Meta, err error)\n```\n\n```go\nfunc NewMetaWithConf(conf conf.MapConf) (meta *Meta, err error)\n```\n\n```go\nfunc NewMetaWithRunnerName(runnerName, metadir, filedonedir, logpath, mode, tagfile string, donefileRetention int) (m *Meta, err error)\n```\n\n```go\nfunc (m *Meta) AddSubMeta(key string, meta *Meta) error\n```\n\n```go\nfunc (m *Meta) AppendDeleteFile(path string) (err error)\n```\n\n```go\nfunc (m *Meta) AppendDoneFile(path string) (err error)\n```\nAppendDoneFile 将处理完的文件写入doneFile中\n\n```go\nfunc (m *Meta) AppendDoneFileInode(path string, inode uint64, offset int64) (err error)\n```\nAppendDoneFileInode 将处理完的文件路径、inode以及完成时间写入doneFile中\n\n```go\nfunc (m *Meta) BufFile() string\n```\nBufFile 返回buf的文件路径\n\n```go\nfunc (m *Meta) BufMetaFile() string\n```\nBufMetaFile 返回buf的meta文件路径\n\n```go\nfunc (m *Meta) CacheLineFile() string\n```\n\n```go\nfunc (m *Meta) CheckExpiredSubMetas(expire time.Duration)\n```\nCheckExpiredSubMetas 仅用于轮询收集所有过期的 submeta，清理操作应通过调用 CleanExpiredSubMetas 方法完成。 一般情况下，应由 reader 实现启动 goroutine 单独调用以避免 submeta 数量过多导致进程被长时间阻塞。 另外，如果 submeta 没有存放在该 meta 的子目录则调用此方法无效\n\n```go\nfunc (m *Meta) CleanExpiredSubMetas(expire time.Duration)\n```\nCleanExpiredSubMetas 清除超过指定过期时长的 submeta 目录，清理数目单次调用存在上限以减少阻塞时间\n\n```go\nfunc (m *Meta) Clear() error\n```\nClear 删除所有meta信息\n\n```go\nfunc (m *Meta) Delete() error\n```\n\n```go\nfunc (m *Meta) DeleteDoneFile(path string) error\n```\n\n```go\nfunc (m *Meta) DeleteFile() string\n```\nDeleteFile 处理完成文件地址，按日进行rotate\n\n```go\nfunc (m *Meta) DoneFile() string\n```\nDoneFile 处理完成文件地址，按日进行rotate\n\n```go\nfunc (m *Meta) ExtraInfo() map[string]string\n```\n\n```go\nfunc (m *Meta) FtSaveLogPath() string\n```\nFtSaveLogPath 返回 ft\\_sender 日志信息记录文件夹路径\n\n```go\nfunc (m *Meta) GetDataSourceTag() string\n```\n\n```go\nfunc (m *Meta) GetDoneFileContent() ([]string, error)\n```\n\n```go\nfunc (m *Meta) GetDoneFileInode(inodeSensitive bool) map[string]int64\n```\n\n```go\nfunc (m *Meta) GetDoneFiles() ([]File, error)\n```\n\n```go\nfunc (m *Meta) GetEncodeTag() string\n```\n\n```go\nfunc (m *Meta) GetEncodingWay() (e string)\n```\nGetEncodingWay 获取文件编码方式\n\n```go\nfunc (m *Meta) GetMode() string\n```\n\n```go\nfunc (m *Meta) GetTagFile() string\n```\n\n```go\nfunc (m *Meta) GetTags() map[string]interface{}\n```\n\n```go\nfunc (m *Meta) IsDoneFile(file string) bool\n```\nIsDoneFile 返回是否是Donefile格式的文件\n\n```go\nfunc (m *Meta) IsExist() bool\n```\n\n```go\nfunc (m *Meta) IsFileMode() bool\n```\n\n```go\nfunc (m *Meta) IsNotExist() bool\n```\nIsNotExist meta 不存在，用来判断是第一次创建\n\n```go\nfunc (m *Meta) IsNotValid() bool\n```\nIsNotValid meta 数据已经过时，用来判断offset文件是否已经不存在，或者meta文件是否损坏\n\n```go\nfunc (m *Meta) IsStatisticFileExist() bool\n```\n\n```go\nfunc (m *Meta) IsStatisticFileNotExist() bool\n```\nIsNotExist meta 不存在，用来判断是第一次创建\n\n```go\nfunc (m *Meta) IsValid() bool\n```\n\n```go\nfunc (m *Meta) LogPath() string\n```\n\n```go\nfunc (m *Meta) MetaFile() string\n```\nMetaFile 返回metaFileoffset 的meta文件地址\n\n```go\nfunc (m *Meta) ReadBuf(buf []byte) (n int, err error)\n```\n\n```go\nfunc (m *Meta) ReadBufMeta() (r, w, bufsize int, err error)\n```\n\n```go\nfunc (m *Meta) ReadCacheLine() ([]byte, error)\n```\n\n```go\nfunc (m *Meta) ReadDBDoneFile(database string) (content []string, err error)\n```\nReadDBDoneFile 读取当前Database已经读取的表\n\n```go\nfunc (m *Meta) ReadOffset() (currFile string, offset int64, err error)\n```\nReadOffset 读取当前读取的文件和offset\n\n```go\nfunc (m *Meta) ReadRecordsFile(recordsFile string) ([]string, error)\n```\nReadRecordsFile 读取当前runner已经读取的表\n\n```go\nfunc (m *Meta) ReadStatistic() (stat Statistic, err error)\n```\n\n```go\nfunc (m *Meta) RemoveSubMeta(key string)\n```\n\n```go\nfunc (m *Meta) Reset() error\n```\n\n```go\nfunc (m *Meta) SetEncodingWay(e string)\n```\nSetEncodingWay 设置文件编码方式，默认为 utf-8\n\n```go\nfunc (m *Meta) StatisticFile() string\n```\nStatisticFile 返回 Runner 统计信息的文件路径\n\n```go\nfunc (m *Meta) SyncDoneFileInode(inodeOffset map[string]int64) (err error)\n```\n\n```go\nfunc (m *Meta) WriteBuf(buf []byte, r, w, bufsize int) (err error)\n```\n\n```go\nfunc (m *Meta) WriteCacheLine(lines string) error\n```\n\n```go\nfunc (m *Meta) WriteOffset(currFile string, offset int64) (err error)\n```\nWriteOffset 将当前文件和offset写入meta中\n\n```go\nfunc (m *Meta) WriteStatistic(stat *Statistic) error\n```\n\n```go\ntype NewSourceRecorder interface {\n\tNewSourceIndex() []SourceIndex\n}\n```\n\n```go\ntype OnceReader interface {\n\tReadDone() bool\n}\n```\n\n```go\ntype Reader interface {\n\t// Name 用于返回读取器的具体名称\n\tName() string\n\t// SetMode 用于设置读取器的匹配模式\n\tSetMode(mode string, v interface{}) error\n\t// Source 用于返回当前读取的数据源\n\tSource() string\n\t// ReadLine 用于向读取器请求返回一行数据\n\tReadLine() (string, error)\n\t// SyncMeta 用于通知读取器保存同步相关元数据\n\tSyncMeta()\n\t// Close 用于关闭读取器\n\tClose() error\n}\n```\nReader 代表了一个通用的行读取器\n\n```go\nfunc NewFileBufReader(conf conf.MapConf, errDirectReturn bool) (reader Reader, err error)\n```\nDeprecated: NewFileBufReader 名字上有歧义，实际上就是NewReader，包括任何类型，保证兼容性，保留\n\n```go\nfunc NewReader(conf conf.MapConf, errDirectReturn bool) (reader Reader, err error)\n```\n\n```go\ntype Registry struct {\n\t// contains filtered or unexported fields\n}\n```\nRegistry reader 的工厂类。可以注册自定义reader\n\n```go\nfunc NewRegistry() *Registry\n```\n\n```go\nfunc (reg *Registry) NewReader(conf conf.MapConf, errDirectReturn bool) (reader Reader, err error)\n```\n\n```go\nfunc (reg *Registry) NewReaderWithMeta(conf conf.MapConf, meta *Meta, errDirectReturn bool) (Reader, error)\n```\n\n```go\nfunc (reg *Registry) RegisterReader(readerType string, constructor Constructor) error\n```\n\n```go\ntype RunTime struct {\n\tStartHour, StartMin int\n\tEndHour, EndMin     int\n}\n```\n\n```go\nfunc ParseRunTime(runTimeStr string) (runTime RunTime, err error)\n```\n\n```go\nfunc ParseRunTimeWithMode(mode string, v interface{}) (runTime RunTime, err error)\n```\n\n```go\nfunc (r RunTime) Equal() bool\n```\n\n```go\nfunc (r RunTime) GreaterThanStart(hour, minute int) bool\n```\n\n```go\nfunc (r RunTime) LessThanEnd(hour, minute int) bool\n```\n\n```go\ntype RunTimeReader interface {\n\tSetRunTime(mode string, v interface{}) error\n}\n```\n\n```go\ntype SourceIndex struct {\n\tSource string\n\tIndex  int\n}\n```\n\n```go\ntype Statistic struct {\n\tReaderCnt       int64                     `json:\"reader_count\"`    // 读取总条数\n\tParserCnt       [2]int64                  `json:\"parser_connt\"`    // [解析成功, 解析失败]\n\tSenderCnt       map[string][2]int64       `json:\"sender_count\"`    // [发送成功, 发送失败]\n\tTransCnt        map[string][2]int64       `json:\"transform_count\"` // [解析成功, 解析失败]\n\tReadErrors      ErrorStatistic            `json:\"read_errors\"`\n\tParseErrors     ErrorStatistic            `json:\"parse_errors\"`\n\tTransformErrors map[string]ErrorStatistic `json:\"transform_errors\"`\n\tSendErrors      map[string]ErrorStatistic `json:\"send_errors\"`\n}\n```\n\n```go\ntype StatsReader interface {\n\t//Name reader名称\n\tName() string\n\tStatus() StatsInfo\n}\n```\nStatsReader 是一个通用的带有统计接口的reader\n\n","path":"github.com/mrbtec/logkit/reader","name":"reader","synopsis":"","isRedistributable":true}
