fsfs

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 7, 2023 License: MIT Imports: 12 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanFiles

func CleanFiles(pattern string, remaining int) error

CleanFiles 按照文件前缀清理文件

pattern: eg /home/work/logs/access_log.log.*
remaining: 文件保留个数,eq :24

func Exists

func Exists(name string) (bool, error)

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

func KeepDirExists

func KeepDirExists(dir string) error

KeepDirExists 保持文件夹存在,若不存在则创建 若路径为文件,则删除,然后创建文件夹

func RotateRuleNames added in v0.0.5

func RotateRuleNames() []string

RotateRuleNames 返回所有切割规则的名称,已按照切割间隔升序排列

func SetRotateRule added in v0.0.5

func SetRotateRule(rules ...*RotateRule) error

SetRotateRule 设置新的切割规则,若和原有的重复,会覆盖掉

Types

type HasFd

type HasFd interface {
	Fd() uintptr
}

HasFd 有实现 Fd 方法

type Keeper

type Keeper struct {
	// FilePath 返回文件地址,必填
	FilePath func() string

	// OpenFile 创建文件的函数,可选
	// 默认为 os.OpenFile(fp, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
	OpenFile func(fp string) (*os.File, error)

	// CheckInterval 检查间隔,可选
	// 默认为 100ms
	CheckInterval time.Duration
	// contains filtered or unexported fields
}

Keeper 保持文件存在

func (*Keeper) AfterChange

func (kf *Keeper) AfterChange(fn func(newFile *os.File))

AfterChange 注册当文件变化后的回调函数

func (*Keeper) BeforeChange

func (kf *Keeper) BeforeChange(fn func(old *os.File))

BeforeChange 注册当文件变化前的回调函数

func (*Keeper) File

func (kf *Keeper) File() *os.File

File 获取文件

func (*Keeper) Start

func (kf *Keeper) Start() error

Start 开始,非阻塞运行

与之对应的有 Stop 方法

func (*Keeper) Stop

func (kf *Keeper) Stop()

Stop 停止运行

type RotateRule added in v0.0.5

type RotateRule struct {
	Fn    func(now time.Time) string
	Name  string
	Cycle time.Duration
}

RotateRule 切割规则

type Rotator

type Rotator struct {

	// ExtFunc 文件后缀生成的自定义函数,可选
	// 优先使用 ExtRule
	ExtFunc func() string

	// NewWriter 对文件的封装
	NewWriter func(w io.Writer) fsio.ResetWriter

	// ExtRule 文件后缀生成的规则,可选
	// 目前支持:1hour、1day、no(默认)
	ExtRule string

	// Path 文件名
	Path string

	// MaxFiles 最多保留文件数,超过的文件将被清理掉,默认值为 24
	// 若值为 -1,则保留所有文件
	MaxFiles int

	// MaxDelay 最大延迟时间,可选,默认为 100ms.
	// 影响文件状态、buffer.
	// 如文件被删除了,则最大间隔 MaxDelay 时长会检查到
	MaxDelay time.Duration
	// contains filtered or unexported fields
}

Rotator 文件具备自动切割的功能

func (*Rotator) AfterChange

func (f *Rotator) AfterChange(fn func(f *os.File))

AfterChange 注册当文件变化时的回调函数

func (*Rotator) Close

func (f *Rotator) Close() error

Close 关闭文件

func (*Rotator) File

func (f *Rotator) File() *os.File

File 获取当前的文件

func (*Rotator) Init

func (f *Rotator) Init() error

Init 初始化

func (*Rotator) Write

func (f *Rotator) Write(p []byte) (n int, err error)

Write 写入

type WatchFile

type WatchFile struct {
	FileName string
	Parser   func(content []byte) error
	// contains filtered or unexported fields
}

WatchFile watch file

func (*WatchFile) Load

func (wf *WatchFile) Load() error

Load load file

func (*WatchFile) OnFileChange

func (wf *WatchFile) OnFileChange(fn func())

OnFileChange register file change callback

func (*WatchFile) Start

func (wf *WatchFile) Start() error

Start watch start

func (*WatchFile) Stop

func (wf *WatchFile) Stop()

Stop watch stop

type Watcher

type Watcher struct {
	Interval time.Duration
	Delay    time.Duration
	// contains filtered or unexported fields
}

Watcher 文件监听

func (*Watcher) Start

func (w *Watcher) Start() error

Start ticker start async

func (*Watcher) Stop

func (w *Watcher) Stop()

Stop ticker stop

func (*Watcher) Watch

func (w *Watcher) Watch(name string, callback func(event WatcherEvent))

Watch add file watch with callback

type WatcherEvent

type WatcherEvent struct {
	FileName string
	Type     WatcherEventType
}

WatcherEvent event for watcher

func (*WatcherEvent) String

func (we *WatcherEvent) String() string

String event desc

type WatcherEventType added in v0.0.6

type WatcherEventType string
const (
	// WatcherEventUpdate contains create and update ent
	WatcherEventUpdate WatcherEventType = "update"

	// WatcherEventDelete  delete event
	WatcherEventDelete WatcherEventType = "delete"
)

Jump to

Keyboard shortcuts

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