utils

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ASSHeader1 = `` /* 137-byte string literal not displayed */

	ASSHeader2 = `[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text`
)

Variables

This section is empty.

Functions

func Center

func Center(s string, width int, fill string) string

将字符串居中

func FindStringIndex

func FindStringIndex(slice []string, target string, caseInsensitive bool, trim bool) int

在 []string 中找到某个字符串的索引 如果未找到,返回 -1

slice: 目标切片 target: 目标字符串 caseInsensitive: 是否忽略大小写 trim: 是否去除空白字符

func GetEndpoint

func GetEndpoint(addr string) string

获取服务器入口

包含协议、主机域名(IP)、端口号(标准端口号可省略) Example1: https://example1.com:8920 Example2: http://example2.com:5224

func GetFileContent

func GetFileContent(filepath string) ([]byte, error)

读取文件内容

func GetHTTPClient

func GetHTTPClient() *http.Client

获取全局 HTTP 客户端(线程安全)

func IsDir

func IsDir(path string) (bool, error)

判断路径是否为文件夹

func IsFile

func IsFile(path string) (bool, error)

判断路径是否为文件

func IsSRT

func IsSRT(content []byte) bool

判断字幕是否为 SRT 格式

func IsURLEncoded

func IsURLEncoded(u string) bool

判断 url 是否经过编码

func MD5Hash

func MD5Hash(raw string) string

MD5编码

对字符串进行MD5哈希运算, 返回十六进制

func PathExists

func PathExists(path string) (bool, error)

判断路径是否存在

func RemoveColorCodes

func RemoveColorCodes(line string) string

RemoveColorCodes 移除字符串中的 ANSI 颜色代码

func ResolveEmbyAPIKVPairs

func ResolveEmbyAPIKVPairs(urlString *string) (string, error)

从 URL 中查询参数中解析 Emby 的 API 键值对

以 xxx=xxx 的字符串形式返回

func SRT2ASS

func SRT2ASS(srtText []byte, style []string) []byte

将 SRT 字幕转换成 ASS 字幕

srtText: SRT 格式字幕文本 style: ASS 字幕样式

func SplitHostPort

func SplitHostPort(hostPort string) (host string, port string)

分离主机域名(IP)和端口号

示例: "example.com:8096" => "example.com", "8096" "[240e:da8:a801:5a47::316]:8096" => "240e:da8:a801:5a47::316" "8096" "192.168.1.1:8096" => "192.168.1.1" "8096"

Types

type JsonChain

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

func NewFromString

func NewFromString(str string, opt *sjson.Options) *JsonChain

func NewJsonChainFromBytes

func NewJsonChainFromBytes(data []byte, opt *sjson.Options) *JsonChain

func NewJsonChainFromBytesWithCopy

func NewJsonChainFromBytesWithCopy(data []byte, opt *sjson.Options) *JsonChain

func NewJsonChainFromReader

func NewJsonChainFromReader(reader io.Reader, opt *sjson.Options) (*JsonChain, error)

func (*JsonChain) Delete

func (json *JsonChain) Delete(path string) *JsonChain

func (*JsonChain) Get

func (json *JsonChain) Get(path string) gjson.Result

func (*JsonChain) Result

func (json *JsonChain) Result() ([]byte, error)

func (*JsonChain) ResultString

func (json *JsonChain) ResultString() (string, error)

func (*JsonChain) ResultToWriter

func (json *JsonChain) ResultToWriter(writer io.Writer) error

func (*JsonChain) Set

func (json *JsonChain) Set(path string, value any) *JsonChain

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

集合对象

func (*Set[T]) Add

func (s *Set[T]) Add(value T)

func (*Set[T]) Adds

func (s *Set[T]) Adds(values ...T)

func (*Set[T]) Contains

func (s *Set[T]) Contains(value T) bool

func (*Set[T]) Equal

func (s *Set[T]) Equal(other SetInterface[T]) bool

func (*Set[T]) Len

func (s *Set[T]) Len() int

func (*Set[T]) Remove

func (s *Set[T]) Remove(value T)

func (*Set[T]) Values

func (s *Set[T]) Values() []T

type SetInterface

type SetInterface[T comparable] interface {
	Add(value T)                      // 添加元素
	Adds(values ...T)                 // 添加多个元素
	Remove(value T)                   // 删除元素
	Contains(value T) bool            // 判断元素是否存在
	Len() int                         // 计算集合元素数量
	Values() []T                      // 获取集合所有元素并排序
	Equal(other SetInterface[T]) bool // 判断两个集合是否相等
}

func NewSet

func NewSet[T comparable]() SetInterface[T]

Jump to

Keyboard shortcuts

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