retention

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package retention 是用在自动清理数据的场景。比如文件、数据表等的自动清理 做好配置后,提供一个名称清单,然后讲根据配置的规则进行识别 最后通过Run函数,可进行对应的处理

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	MaxRetain      int      `json:"max_retain" yaml:"max_retain" ini:"max_retain"`                // 最大保留数量
	Prefix         string   `json:"prefix" yaml:"prefix" ini:"prefix"`                            // 项目前缀
	Delimiter      string   `json:"delimiter" yaml:"delimiter" ini:"delimiter"`                   // 分隔符,默认为"_"
	TimeFormat     string   `json:"time_format" yaml:"time_format" ini:"time_format"`             // 时间格式,默认为"20060102"
	Order          Order    `json:"order" yaml:"order" ini:"order"`                               // 排序顺序
	Criteria       Criteria `json:"criteria" yaml:"criteria" ini:"criteria"`                      // 排序依据
	IgnoreSuffixes []string `json:"ignore_suffixes" yaml:"ignore_suffixes" ini:"ignore_suffixes"` // 要忽略的后缀列表
}

Config 保留管理器配置

type Criteria

type Criteria string

Criteria 定义排序依据类型

const (
	ByTime   Criteria = "time"   // 按时间排序
	ByNumber Criteria = "number" // 按数字排序
	ByName   Criteria = "name"   // 按名称排序
)

type Manager

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

Manager 保留管理器

func New

func New(config Config) *Manager

New 创建新的保留管理器

func (*Manager) AddItems

func (m *Manager) AddItems(names []string) *Manager

AddItems 添加要管理的项目

func (*Manager) Run

func (m *Manager) Run(onDelete func(string) error) error

Run 执行保留管理,传入删除回调函数

func (*Manager) WithCustomExtractor

func (m *Manager) WithCustomExtractor(fn func(string) any) *Manager

WithCustomExtractor 设置自定义键提取器

type Order

type Order bool

Order 定义排序顺序类型

const (
	Descending Order = false // 降序,删除数字小的
	Ascending  Order = true  // 升序, 删除数字大的
)

Jump to

Keyboard shortcuts

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