xfile

package
v1.3.7 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 License: MulanPSL-2.0 Imports: 14 Imported by: 5

README

xfile

介绍
  • 文件处理

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendContent added in v1.1.3

func AppendContent(path string, content string) (int, error)

AppendContent 向文件里追加内容

func CopyFile

func CopyFile(src, dst string, isFirstDel ...bool) (err error)

CopyFile 复制文件

func Create added in v1.0.1

func Create(path string) (*os.File, error)

Create 可以新建文件/目录 注: 需要外部调用 Close 进行关闭

func CronParseLogFile added in v1.1.9

func CronParseLogFile(collectLog string, offset ...int) ([]string, error)

CronParseLogFile 定时解析增量 log, 返回每行的内容

func Exists added in v1.0.1

func Exists(path string) bool

Exists 判断文件/目录是否存在

func GetContent added in v1.1.4

func GetContent(path string) (string, error)

GetContent 获取文件内容

func GetProjectDir

func GetProjectDir(projectName string) string

GetProjectDir 获取项目路径

func Open added in v1.1.5

func Open(path string) (*os.File, error)

Open

func OpenFile added in v1.1.5

func OpenFile(path string, flag int, perm os.FileMode) (*os.File, error)

OpenFile

func ParseFileFormat

func ParseFileFormat(fileName string) string

ParseFileFormat 解析文件格式

func PutContent added in v1.1.3

func PutContent(path string, content string) (int, error)

PutContents 向文件里追加内容

func Remove added in v1.1.9

func Remove(path string) error

Remove 移除

func SetLogger added in v1.2.21

func SetLogger(l Logger)

SetLogger 设置 log

Types

type FileHandle added in v1.0.2

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

FileHandle

func NewFileHandle added in v1.1.3

func NewFileHandle(path string, expire ...time.Time) *FileHandle

NewFileHandle

func (*FileHandle) AppendContent added in v1.2.11

func (fh *FileHandle) AppendContent(content string) (int, error)

AppendContent 向文件写入内容, 内容追加

func (*FileHandle) Clean added in v1.2.21

func (fh *FileHandle) Clean() error

Clean 清空文件内容

func (*FileHandle) Close added in v1.0.2

func (fh *FileHandle) Close() error

Close 关闭文件句柄

func (*FileHandle) Exists added in v1.1.7

func (fh *FileHandle) Exists() bool

Exists 判断文件存在不

func (*FileHandle) GetContent added in v1.2.11

func (fh *FileHandle) GetContent() (string, error)

GetContent 查询内容

func (*FileHandle) GetFile added in v1.0.2

func (fh *FileHandle) GetFile(flag ...int) *os.File

GetFile 获取文件操作句柄

func (*FileHandle) Initf added in v1.1.3

func (fh *FileHandle) Initf(flag int, perm ...os.FileMode) error

Initf 初始化文件句柄

func (*FileHandle) IsExpire added in v1.1.3

func (fh *FileHandle) IsExpire() bool

IsExpire 过期

func (*FileHandle) PutContent added in v1.2.11

func (fh *FileHandle) PutContent(content string) (int, error)

PutContent 向文件里写内容, 只会覆写

func (*FileHandle) ResetSeek added in v1.2.11

func (fh *FileHandle) ResetSeek(seekFlag ...int) (int64, error)

ResetSeek 重置油标

type FileInfo added in v1.3.4

type FileInfo struct {
	AbsolutePath string // 本地绝对路径
	RelativePath string // 相对项目的路径
	Filename     string // 文件名
}

func (*FileInfo) GetFilePath added in v1.3.4

func (f *FileInfo) GetFilePath() string

type FilePool

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

FilePool 文件池

func NewFilePool

func NewFilePool(size ...int) *FilePool

NewFilePool 初始化文件池, 最大 256 个 默认会按 defaultExpireDur 进行淘汰 注: 使用结束需要调用 Close 释放还在内存中的句柄

func (*FilePool) Close added in v1.2.7

func (fp *FilePool) Close()

Close 关闭

func (*FilePool) Get

func (fp *FilePool) Get(path string, flag int, perm ...os.FileMode) (*FileHandle, error)

Get 获取文件句柄; 如果不存在就会新打开文件句柄; 如果文件/目录不存在会自动创建 注: 1. 调用完需要调用 Put 才能进行复用, 同时句柄不能 Close

  1. 如果打算不用了的话, 必须调用 *FileHandle.Close 方法进行释放句柄, 防止内存泄露

func (*FilePool) GetFile2Open added in v1.2.26

func (fp *FilePool) GetFile2Open(filename string, flag int) int

GetFile2Open 获取文件对应的文件句柄打开数

func (*FilePool) GetFile2OpenMap added in v1.2.26

func (fp *FilePool) GetFile2OpenMap() map[string]int

GetFile2OpenMap 获取池中所有文件打开的句柄数

func (*FilePool) MaxFhCount added in v1.2.6

func (fp *FilePool) MaxFhCount(count int) *FilePool

MaxFhCount 设置相同 path 时, 最大文件句柄数

func (*FilePool) Print added in v1.2.6

func (fp *FilePool) Print(is bool) *FilePool

Print 是否打印 log level 为 info 的 log

func (*FilePool) Put

func (fp *FilePool) Put(fh *FileHandle, expire ...time.Time)

Put 归还

type Logger added in v1.2.21

type Logger interface {
	Info(v ...interface{})
	Infof(format string, v ...interface{})
	Error(v ...interface{})
	Errorf(format string, v ...interface{})
}

type ParseFile added in v1.3.4

type ParseFile struct {
	Filenames []*FileInfo
	// contains filtered or unexported fields
}

func NewParseFile added in v1.3.4

func NewParseFile() *ParseFile

func (*ParseFile) Check added in v1.3.4

func (p *ParseFile) Check() bool

Check 验证

func (*ParseFile) GetProFiles added in v1.3.4

func (p *ParseFile) GetProFiles() []*FileInfo

GetProFiles 获取项目路径

func (*ParseFile) Len added in v1.3.4

func (p *ParseFile) Len() int

Len 返回解析的总数

func (*ParseFile) Null added in v1.3.4

func (p *ParseFile) Null() bool

func (*ParseFile) ParseHasSuffixFiles added in v1.3.4

func (p *ParseFile) ParseHasSuffixFiles(path string, fileSuffix string) *ParseFile

ParseHasSuffixFiles 解析项目中包含某后缀的文件

func (*ParseFile) Reset added in v1.3.4

func (p *ParseFile) Reset()

func (*ParseFile) SetSkipTopDir added in v1.3.4

func (p *ParseFile) SetSkipTopDir(dirs ...string) *ParseFile

SetSkipTopDir 设置需要跳过的一级文件夹 dirs 多个通过逗号隔开

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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