xfile

package
v1.2.28 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 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 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(fh *FileHandle) 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{})
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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