Documentation
¶
Index ¶
- Constants
- func HelpDoc() string
- func ProxyM3U(m3uLink string, header http.Header, proxyTs bool, tsProxyMode TsProxyMode, ...) (string, error)
- func ProxyTs(c *gin.Context)
- func RegisterHandler(handler Handler)
- func RemoveM3UProxyCache(url string)
- type Cacher
- type CacherOption
- func WithCacheTimeout[T any](timeout time.Duration) CacherOption[T]
- func WithCalcCacheKey[T any](f func(T) string) CacherOption[T]
- func WithFetchValue[T any](f func(T) (string, error)) CacherOption[T]
- func WithRecoverCacheKey[T any](f func(string) (T, bool)) CacherOption[T]
- func WithRemoveInterval[T any](removeInterval time.Duration) CacherOption[T]
- func WithUpdateComplete[T any](f func(success, fail, remove int)) CacherOption[T]
- func WithUpdateInterval[T any](updateInterval time.Duration) CacherOption[T]
- type CommonM3U8
- func (cm *CommonM3U8) ChannelSlice(infos map[string][]subm3u.Info) []string
- func (cm *CommonM3U8) MatchChannel(infos map[string][]subm3u.Info, chName, format string) (subm3u.Info, error)
- func (cm *CommonM3U8) ResolveSub(client *https.CacheClient, subAddr string, headers http.Header) (map[string][]subm3u.Info, error)
- type HandleParams
- type HandleResult
- type Handler
- type PreCacheReq
- type ResultType
- type TsProxyMode
Constants ¶
const ( Env_CustomTsProxyEnableKey = "custom_ts_proxy_enable" // 是否启用自定义的代理接口 Env_CustomTsProxyHostKey = "custom_ts_proxy_host" // 自定义代理接口地址 DefaultProxyUA = "libmpv" // 代理的默认客户端标识 )
Variables ¶
This section is empty.
Functions ¶
func ProxyM3U ¶ added in v1.2.0
func ProxyM3U(m3uLink string, header http.Header, proxyTs bool, tsProxyMode TsProxyMode, clientHost string) (string, error)
ProxyM3U 代理 m3u 地址
代理成功时会返回代理后的 m3u 文本
func RegisterHandler ¶ added in v1.2.0
func RegisterHandler(handler Handler)
RegisterHandler 注册处理器到内存中
func RemoveM3UProxyCache ¶ added in v1.21.4
func RemoveM3UProxyCache(url string)
RemoveM3UProxyCache 移除 m3u 订阅缓存
Types ¶
type Cacher ¶ added in v1.16.0
type Cacher[T any] struct { // CalcCacheKey 计算 cacheKey 的钩子, 需要调用方实现 CalcCacheKey func(T) string // RecoverCacheKey 恢复 cacheKey 的钩子, 需要调用方实现 RecoverCacheKey func(string) (T, bool) // FetchValue 获取指定入参的最新值钩子, 需要调用方实现 FetchValue func(T) (string, error) // UpdateComplete 缓存刷新完成调用的钩子, 需要调用方实现 UpdateComplete func(success, fail, remove int) // contains filtered or unexported fields }
Cacher 通用的解析缓存器, 避免客户端频繁请求 可通过泛型指定业务请求参数
func NewCacher ¶ added in v1.16.0
func NewCacher[T any](opts ...CacherOption[T]) *Cacher[T]
NewCacher 初始化一个缓存器
type CacherOption ¶ added in v1.16.0
CacherOption 用于初始化 Cacher 对象
func WithCacheTimeout ¶ added in v1.16.0
func WithCacheTimeout[T any](timeout time.Duration) CacherOption[T]
WithCacheTimeout 设置缓存过期时间
某个值超过这个时间没有读取时, 就将其移除
受缓存过期检查间隔影响, 这个值不是百分百准确的
func WithCalcCacheKey ¶ added in v1.16.0
func WithCalcCacheKey[T any](f func(T) string) CacherOption[T]
WithCalcCacheKey 设置 cacheKey 计算方法
func WithFetchValue ¶ added in v1.16.0
func WithFetchValue[T any](f func(T) (string, error)) CacherOption[T]
WithFetchValue 设置获取最新值的方法, 用于刷新缓存
func WithRecoverCacheKey ¶ added in v1.16.0
func WithRecoverCacheKey[T any](f func(string) (T, bool)) CacherOption[T]
WithRecoverCacheKey 设置 cacheKey 恢复方法
func WithRemoveInterval ¶ added in v1.16.0
func WithRemoveInterval[T any](removeInterval time.Duration) CacherOption[T]
WithRemoveInterval 设置缓存过期检查间隔
func WithUpdateComplete ¶ added in v1.16.0
func WithUpdateComplete[T any](f func(success, fail, remove int)) CacherOption[T]
WithUpdateComplete 设置缓存更新完成的统计数据方法
func WithUpdateInterval ¶ added in v1.16.0
func WithUpdateInterval[T any](updateInterval time.Duration) CacherOption[T]
WithUpdateInterval 设置缓存刷新时间间隔
type CommonM3U8 ¶ added in v1.19.0
type CommonM3U8 struct{}
CommonM3U8 封装 m3u8 通用解析逻辑
func (*CommonM3U8) ChannelSlice ¶ added in v1.21.0
func (cm *CommonM3U8) ChannelSlice(infos map[string][]subm3u.Info) []string
ChannelSlice 获取频道信息列表中所有可用的频道
func (*CommonM3U8) MatchChannel ¶ added in v1.19.0
func (cm *CommonM3U8) MatchChannel(infos map[string][]subm3u.Info, chName, format string) (subm3u.Info, error)
MatchChannel 匹配频道指定频道信息
func (*CommonM3U8) ResolveSub ¶ added in v1.19.0
func (cm *CommonM3U8) ResolveSub(client *https.CacheClient, subAddr string, headers http.Header) (map[string][]subm3u.Info, error)
ResolveSub 解析 m3u8 订阅地址, 返回频道信息
type HandleParams ¶
type HandleParams struct {
ChName string // 频道简称
UrlEnv string // 存储远程地址的环境变量名
ProxyM3U bool // 是否代理 m3u
ProxyTs bool // 是否代理 ts
TsProxyMode // ts 代理模式
Format string // 要处理的直播格式
ClientIp string // 客户端 ip
ClientHost string // 客户端请求的主机前缀
Headers http.Header // 请求头
}
HandleParams 处理参数
type HandleResult ¶
type HandleResult struct {
Type ResultType // 响应类型
Url string // 响应地址, 用于重定向
Code int // 响应状态码, 用于本地代理
Header http.Header // 响应头, 用于本地代理
Body []byte // 响应体, 用于本地代理
}
HandleResult 处理器的处理结果
func M3U8Result ¶ added in v1.14.0
func M3U8Result(url string, params HandleParams) (HandleResult, error)
M3U8Result 根据处理器参数返回 m3u 地址的处理结果
type Handler ¶
type Handler interface {
// Handle 处理直播, 返回一个用于重定向的远程地址
Handle(HandleParams) (HandleResult, error)
// Name 处理器名称
Name() string
// HelpDoc 处理器说明文档
HelpDoc() string
// SupportProxy 是否支持 m3u 代理
//
// 如果返回 true, 会自动在帮助文档中加入标记
SupportM3UProxy() bool
// SupportCustomHeaders 是否支持自定义请求头
//
// 如果返回 true, 会自动在帮助文档中加入标记
SupportCustomHeaders() bool
// Enabled 标记处理器是否是启用状态
Enabled() bool
}
Handler 直播响应处理器
type PreCacheReq ¶ added in v1.16.0
type PreCacheReq[T any] struct { // T 调用方的业务参数 T T // contains filtered or unexported fields }
PreCacheReq 预缓存请求结构, 用于并发排队
type ResultType ¶
type ResultType string
ResultType 处理器的处理结果
const ( ResultRedirect ResultType = "redirect" // 重定向 ResultProxy ResultType = "proxy" // 本地代理 )
type TsProxyMode ¶ added in v1.14.0
type TsProxyMode string
var ( ModeCustom TsProxyMode = "custom" // 使用自定义的 ts 代理接口策略 ModeLocal TsProxyMode = "local" // 使用本地代理策略 )