tools

package
v1.2.92 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: BSD-2-Clause Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HSetRecord    = "hSetRecord"
	HGetAllRecord = "hGetAllRecord"
	HDeleteRecord = "hDeleteRecord"
)
View Source
const LuaHDeleteRecord = `` /* 836-byte string literal not displayed */
View Source
const LuaHGetAllRecord = `` /* 851-byte string literal not displayed */
View Source
const LuaHSetRecord = `` /* 647-byte string literal not displayed */

Variables

View Source
var (
	Logger *zap.Logger
)

Functions

func AppendToFile

func AppendToFile(filePath string, data []byte) error

AppendToFile appendToFile 将数据追加到文件末尾

func Base64EncodeAndReplace

func Base64EncodeAndReplace(roomNumber string) string

func CheckAndCreateDir

func CheckAndCreateDir(dirPath string) error

CheckAndCreateDir 检查指定的目录是否存在,如果不存在则创建它。

func CleanString

func CleanString(origin string) string

func ConcatMediaFile added in v1.2.30

func ConcatMediaFile(ctx context.Context, fileList []string, fileName, storagePath string) error

func CopyFile

func CopyFile(src string, dstDir string) error

CopyFile appendToFile 将数据追加到文件末尾 CopyFile 拷贝文件到指定目录

func ExistDirectory

func ExistDirectory(path string) error

func ExtractPath

func ExtractPath(fullPath string) string

func ExtractURLPath

func ExtractURLPath(urlStr string, config *ExtractPathConfig) (string, error)

ExtractURLPath 从URL字符串中提取路径 参数:

urlStr - 要解析的URL字符串
config - 提取配置(传 nil 使用默认配置)

返回值:

string - 提取到的路径
error  - 解析错误

func FileExists

func FileExists(path string) (bool, error)

func GenerateRtmpUrl

func GenerateRtmpUrl(config *RtmpConfig) string

func GenerateTencentRtmpUrl

func GenerateTencentRtmpUrl(config *RtmpConfig) string

func GenerateUUID

func GenerateUUID() string

func GetAllQueuesUrl

func GetAllQueuesUrl(domain, port, vhost string) string

func GetExchangeBindingQueueUrl

func GetExchangeBindingQueueUrl(domain, port, exchange, vhost string) string

func GetFileSize

func GetFileSize(filePath string) (int64, error)

func GetLogger

func GetLogger() *zap.Logger

GetLogger 获取 Logger,未初始化则自动初始化

func GetMediaParameters

func GetMediaParameters(media Media, resolutionLevel int) (int32, int32, int32, int32, int32, int32)

func GetQueueInfoUrl

func GetQueueInfoUrl(domain, port, queue, vhost string) string

func GetRandomString

func GetRandomString(length int) (string, error)

func GetRecordFilePath

func GetRecordFilePath(config *RecordConfig) string

func GetRecordFileUrl

func GetRecordFileUrl(domain, path string) string

func GetResolution

func GetResolution(ctx context.Context, filePath string) (*modelStruct.Resolution, string, string, error)

func GetSecondTimeStamp

func GetSecondTimeStamp() int64

func GetTCTaskIDKey

func GetTCTaskIDKey(prefix, appID, roomID, taskID string) string

func GetTcRecordFilePath

func GetTcRecordFilePath(config *RecordConfig) string

func GetTimeStamp

func GetTimeStamp() int64

func GetTimeString

func GetTimeString(format string) string

获取格式化时间字符串(默认本地时区)

func GetUTCTimeString

func GetUTCTimeString(format string) string

获取UTC时间字符串(带时区信息)

func GetVideoDuration

func GetVideoDuration(ctx context.Context, filePath string) (int64, string, error)

GetVideoDuration 获取视频时长

func GetVideoDurationArgs

func GetVideoDurationArgs(ctx context.Context, filePath string) []string

func HasAudio

func HasAudio(ctx context.Context, filePath string) (bool, string, string, error)

func InitLogger

func InitLogger(config LoggerConfig) error

InitLogger 初始化日志器

func JoinStrings

func JoinStrings(s ...string) string

带缓冲区的优化版本(适合高频调用)

func MustGetLogger

func MustGetLogger() *zap.Logger

MustGetLogger 获取 Logger,未初始化则自动初始化

func ReadLines added in v1.2.40

func ReadLines(filename string) ([]string, error)

ReadLines 从指定文件中读取每一行,并返回一个字符串切片

func RecoverPanic added in v1.2.67

func RecoverPanic(ctx context.Context)

RecoverPanic 捕获 panic 并记录日志

func RemoveDir

func RemoveDir(dirPath string) error

func RemoveFile

func RemoveFile(filePath string) error

func Retry

func Retry(req *RetryableRequest) error

通用重试执行器

func RetryString

func RetryString(attempts int, sleep time.Duration, fn func() (interface{}, error)) (interface{}, error)

Retry 封装重试逻辑

func SafeGo

func SafeGo(ctx context.Context, handler func(context.Context))

SafeGo 安全协程(自动捕获 panic 并支持 context 控制)

func SafeGoWithParams

func SafeGoWithParams(ctx context.Context, handler func(context.Context, ...interface{}), params ...interface{})

SafeGoWithParams 支持参数的安全协程

func ScheduleDaily

func ScheduleDaily(targetHour, targetMinute, targetSecond int, task func())

ScheduleDaily 启动每日定时任务

func ScheduleWeekly

func ScheduleWeekly(targetWeekday time.Weekday, targetHour, targetMinute int, task func())

scheduleWeekly 启动一个周期性任务,每周特定时间执行

func SendRequest

func SendRequest(connectionRequest ConnectionRequest, request *modelStruct.RequestModel, sendConfig SendConfig)

func SwitchToTime

func SwitchToTime(timestamp string) (int64, error)

func Sync

func Sync() error

Sync 同步日志缓冲区

func TruncateString

func TruncateString(s string, maxLen int) string

func WithTraceID

func WithTraceID(traceID string) *zap.Logger

WithTraceID 返回带 trace_id 的 Logger

Types

type CommandExecutor

type CommandExecutor struct {
	Command string
	Args    []string
	Stdout  bytes.Buffer
	Stderr  bytes.Buffer
}

CommandExecutor 用于执行命令并捕获输出

func NewCommandExecutor

func NewCommandExecutor() *CommandExecutor

NewCommandExecutor 创建一个新的 CommandExecutor 实例

func (*CommandExecutor) Output

func (ce *CommandExecutor) Output() string

Output 获取标准输出

func (*CommandExecutor) Run

func (ce *CommandExecutor) Run(ctx context.Context, command string, args ...string) error

Run 执行命令并等待其完成

func (*CommandExecutor) StderrOutput

func (ce *CommandExecutor) StderrOutput() string

StderrOutput 获取标准错误输出

type ConnectionRequest

type ConnectionRequest interface {
	Request(request *modelStruct.RequestModel, response *modelStruct.ResponseModel, ctx context.Context) error
}

type ExtractPathConfig

type ExtractPathConfig struct {
	TrimLeadingSlash bool // 是否去除开头的斜杠
	DecodePath       bool // 是否解码百分比编码(如 %20 → 空格)
}

ExtractPathConfig 配置参数结构体

type LoggerConfig

type LoggerConfig struct {
	LogPath    string
	LogLevel   string
	MaxSize    int
	MaxBackups int
	MaxAge     int
	Compress   bool
	IsStdout   bool
}

type Media

type Media struct {
	RecordFrameRate int32
	RecordWidth     int32
	RecordHeight    int32
	RecordBitrate   int32
	Resolutions     map[int]Resolution
}

func GetDefaultMedia

func GetDefaultMedia() Media

type RecordConfig

type RecordConfig struct {
	AppID        string
	RoomID       string
	TaskID       string
	TcTaskID     string
	RecordType   int
	FirstPrefix  string
	SecondPrefix string
	EnvType      string
	ObjFileName  string
	FileName     string
}

type Resolution

type Resolution struct {
	Width     int32
	Height    int32
	Bitrate   int32
	FrameRate int32
}

type RetryableRequest

type RetryableRequest struct {
	MaxRetries    int                              // 最大重试次数(默认3)
	OperationName string                           // 操作名称(用于日志)
	Context       context.Context                  // 上下文控制
	ReqExecutor   func() error                     // 请求执行函数
	ErrChecker    func() error                     // 错误检查函数
	ErrCallback   func(err error, index int) error // 错误回调函数(可选)
	DelayStrategy func(int) time.Duration          // 延时策略(可选)
}

type RtmpConfig

type RtmpConfig struct {
	AppID       string
	StreamName  string
	Domain      string
	SecretKey   string
	MaxIdleTime int64
	Format      string
}

type SendConfig

type SendConfig struct {
	Url    string
	Mobile string
	RoomID string
	Method string
	Logger *zap.Logger
}

type TraceIDKey added in v1.2.12

type TraceIDKey struct{}

Jump to

Keyboard shortcuts

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