utils

package
v1.0.0-rc.58 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PeriodDay     = "day"
	PeriodWeek    = "week"
	PeriodMonth   = "month"
	PeriodQuarter = "quarter"
	PeriodYear    = "year"
)

统计的分段:天、周(从周一开始)、月、季度(从 1、4、7、10 月开始)、年。刷流收益与辅种统计共用。

Variables

View Source
var CSTLocation = time.FixedZone("CST", 8*3600)

CSTLocation is the China Standard Time timezone (UTC+8). All PT sites (M-Team, HDSky, SpringSunday, HDDolby, etc.) return times in CST.

View Source
var PeriodLimits = map[string]PeriodLimit{
	PeriodDay:     {30, 366},
	PeriodWeek:    {12, 104},
	PeriodMonth:   {12, 60},
	PeriodQuarter: {8, 40},
	PeriodYear:    {5, 20},
}

PeriodLimits 是每种分段默认、最多几段。

Functions

func CheckDirectory

func CheckDirectory(path string) (exists, empty bool, err error)

CheckDirectory 检查目录是否存在且为空 返回值: - exists: 目录是否存在 - empty: 目录是否为空(如果存在) - err: 错误信息(如果存在)

func DirectoryExists

func DirectoryExists(path string) (bool, error)

func FormatBytes

func FormatBytes(n int64) string

FormatBytes 把字节数格式化成 IEC 单位(B、KiB、MiB、GiB、TiB、PiB),1 KiB 以上保留两位小数。

func IsDirectoryEmpty

func IsDirectoryEmpty(path string) (bool, error)

func ParseTimeInCST added in v0.3.0

func ParseTimeInCST(layout, value string) (time.Time, error)

ParseTimeInCST parses a time string in CST timezone.

func PeriodAdd

func PeriodAdd(start time.Time, gran string, n int) time.Time

PeriodAdd 是从 start(某一段的第一天)往后 n 段的第一天(n 可以是负数)。

func PeriodStart

func PeriodStart(t time.Time, gran string) time.Time

PeriodStart 是 t 所在那一段的第一天(零点,t 的时区)。不认识的分段按天。

func RedactURLError

func RedactURLError(err error) error

RedactURLError 把错误链里 *url.Error 的地址换成脱敏后的地址,返回原错误。 net/http 的传输错误会把完整请求地址(RSS、种子下载地址常带 passkey)写进错误文本。 要在包装之前调用:fmt.Errorf 包装时就把错误文本定下了。

func ResolveDownloadBase added in v0.1.1

func ResolveDownloadBase(home, work, dir string) (string, error)

func SanitizeURL added in v0.6.0

func SanitizeURL(rawURL string) string

SanitizeURL 对 URL 中的敏感查询参数进行脱敏处理 返回脱敏后的 URL 字符串,敏感参数值会被替换为 "***" 如果解析失败,返回 "<invalid-url>"

func SubPathFromTag added in v0.1.1

func SubPathFromTag(tag string) string

Types

type Locker added in v0.0.14

type Locker interface {
	Lock() error
	Unlock() error
	File() *os.File
}

定义统一接口

func NewLocker added in v0.0.14

func NewLocker(lockPath string) (Locker, error)

type PeriodLimit

type PeriodLimit struct{ Default, Max int }

PeriodLimit 是一种分段默认几段、最多几段。

Directories

Path Synopsis
Package httpclient 提供基于 github.com/sunerpy/requests 的 HTTP 客户端连接池管理
Package httpclient 提供基于 github.com/sunerpy/requests 的 HTTP 客户端连接池管理

Jump to

Keyboard shortcuts

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