utils

package
v0.19.2 Latest Latest
Warning

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

Go to latest
Published: May 15, 2025 License: MIT Imports: 17 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidName = errors.New("webhook/utils: invalid join tag value")
	ErrNotPointer  = errors.New("webhook/utils: value must be a pointer to struct")
)
View Source
var ErrInvalidURL = errors.New("webhook/file: invalid URL")

Functions

func Join added in v0.15.0

func Join(in any) error

func LoadEdges added in v0.15.0

func LoadEdges(in reflect.Type) [][2]int

func NewJoin added in v0.15.0

func NewJoin[T any](in T) (*T, error)

func NextTimeDuration added in v0.15.0

func NextTimeDuration(hour, min, sec int) time.Duration

func ParseEdges added in v0.15.0

func ParseEdges(elem reflect.Type) (edges [][2]int)

func Shell added in v0.15.0

func Shell(s string, dir string, keep bool) ([]string, error)

func SplitLines added in v0.14.0

func SplitLines(s string) (r []string)

func StrToAny added in v0.15.0

func StrToAny(conds []string) []any

Types

type Client added in v0.19.0

type Client interface {
	// 在选择客户端时,会根据主机名进行匹配
	// 返回值包含 example.com 时会匹配所有 *.example.com 的请求
	Hosts() []string

	// 自定义请求方法,可以添加请求头、鉴权参数、Cookies 之类
	Get(url string) (*http.Response, error)
}

客户端接口

type DateHook added in v0.15.0

type DateHook struct {
	// 输出日志文件的路径
	// 会利用日志事件的时间进行格式化处理
	// 参考值 "logs/2006-01-02.log"
	Format string

	// 日志等级
	// 为空默认 logrus.AllLevels
	LogLevels []logrus.Level
	// contains filtered or unexported fields
}

以天为单位分割日志的钩子 为 logrus.Logger 添加此钩子仅能实现日志刷新,如果要写入还需将其设为 logrus.Logger.Out

func (*DateHook) Close added in v0.15.0

func (d *DateHook) Close() error

关闭日志

func (*DateHook) Fire added in v0.15.0

func (d *DateHook) Fire(entry *logrus.Entry) (err error)

func (DateHook) Levels added in v0.15.0

func (d DateHook) Levels() []logrus.Level

func (*DateHook) Write added in v0.15.0

func (d *DateHook) Write(p []byte) (int, error)

写入日志

type Downloader added in v0.19.0

type Downloader struct {
	// 保存文件的根目录
	Root string
	// contains filtered or unexported fields
}

下载器

对于一个地址为 https://www.example.com/public/data.txt 文件 会保存在 $Root/www.example.com/public/data.txt

func NewDownloader added in v0.19.0

func NewDownloader(root string, client ...Client) *Downloader

func (*Downloader) Download added in v0.19.0

func (d *Downloader) Download(url string) (http.File, error)

下载文件

func (*Downloader) Open added in v0.19.0

func (d *Downloader) Open(name string) (http.File, error)

打开文件

会先尝试在本地访问,如果不存在再从网络下

func (*Downloader) Register added in v0.19.0

func (d *Downloader) Register(client ...Client)

注册客户端

type JoinError added in v0.19.0

type JoinError []error

func (JoinError) Error added in v0.19.0

func (e JoinError) Error() string

func (JoinError) Unwrap added in v0.19.0

func (e JoinError) Unwrap() []error

type Node added in v0.15.0

type Node struct {
	Target *Node
	// contains filtered or unexported fields
}

func (*Node) Depth added in v0.15.0

func (n *Node) Depth() int

Jump to

Keyboard shortcuts

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