Documentation ¶
Overview ¶
Package report 提供了对数据埋点及上报的实现
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DataBuried ¶
type DataBuried[DataID comparable, Data any] struct { // contains filtered or unexported fields }
DataBuried 数据埋点
- 数据埋点通常用于统计不同类型的数据,例如用户数据、商城数据等
func NewDataBuried ¶
func NewDataBuried[DataID comparable, Data any](name string, hitLogic HitLogic[Data], options ...DataBuriedOption[DataID, Data]) *DataBuried[DataID, Data]
NewDataBuried 创建一个数据埋点
func (*DataBuried[DataID, Data]) GetData ¶
func (slf *DataBuried[DataID, Data]) GetData(id DataID) Data
GetData 获取数据
func (*DataBuried[DataID, Data]) GetName ¶
func (slf *DataBuried[DataID, Data]) GetName() string
GetName 获取名称
func (*DataBuried[DataID, Data]) GetSize ¶
func (slf *DataBuried[DataID, Data]) GetSize() int
GetSize 获取已触发该埋点的id数量
func (*DataBuried[DataID, Data]) Hit ¶
func (slf *DataBuried[DataID, Data]) Hit(id DataID, data Data)
Hit 命中数据埋点
type DataBuriedOption ¶
type DataBuriedOption[DataID comparable, Data any] func(buried *DataBuried[DataID, Data])
func WithDataBuriedStorage ¶
func WithDataBuriedStorage[DataID comparable, Data any](getData func(id DataID) Data, setData func(id DataID, data Data)) DataBuriedOption[DataID, Data]
WithDataBuriedStorage 通过特定的存储模式创建数据埋点
- 默认情况下埋点数据存储在内存中
- 使用该方式可以将埋点存储存储在其他如数据库、消息队列中
type GlobalBuried ¶
type GlobalBuried[Data any] struct { // contains filtered or unexported fields }
GlobalBuried 全局埋点
- 全局埋点适用于活跃用户数等统计
func NewGlobalBuried ¶
func NewGlobalBuried[Data any](name string, hitLogic HitLogic[Data], options ...GlobalBuriedOption[Data]) *GlobalBuried[Data]
NewGlobalBuried 创建一个全局埋点
type GlobalBuriedOption ¶
type GlobalBuriedOption[Data any] func(buried *GlobalBuried[Data])
func WithGlobalBuriedStorage ¶
func WithGlobalBuriedStorage[DataID comparable, Data any](getData func() Data, setData func(data Data)) GlobalBuriedOption[Data]
WithGlobalBuriedStorage 通过特定的存储模式创建全局埋点
- 默认情况下埋点数据存储在内存中
- 使用该方式可以将埋点存储存储在其他如数据库、消息队列中
type HitLogic ¶
type HitLogic[Data any] func(data Data, input Data) Data
HitLogic 埋点命中逻辑
- data: 当前数据
- input: 新输入的数据
- return: 设置当前数据
func WithHitLogicCover ¶
WithHitLogicCover 通过覆盖原数值的方式处理命中事件
type Reporter ¶
type Reporter struct {
// contains filtered or unexported fields
}
Reporter 数据上报器
func NewReporter ¶
func NewReporter(reportHandle func() error, options ...ReporterOption) *Reporter
type ReporterOption ¶
type ReporterOption func(reporter *Reporter)
func WithReporterErrorHandle ¶
func WithReporterErrorHandle(errorHandle func(reporter *Reporter, err error)) ReporterOption
func WithReporterStrategies ¶
func WithReporterStrategies(strategies ...ReporterStrategy) ReporterOption
WithReporterStrategies 通过特定上报策略进行创建
func WithReporterTicker ¶
func WithReporterTicker(ticker *timer.Ticker) ReporterOption
WithReporterTicker 通过特定的定时器创建上报器
type ReporterStrategy ¶
type ReporterStrategy func(reporter *Reporter)
ReporterStrategy 上报器策略
func StrategyFixedTime ¶ added in v0.0.16
func StrategyFixedTime(hour, min, sec int) ReporterStrategy
StrategyFixedTime 将在每天的固定时间上报
func StrategyLoop ¶ added in v0.0.16
func StrategyLoop(t time.Duration) ReporterStrategy
StrategyLoop 循环上报
- 将在创建后上报一次,并且在每隔一段时间后继续上报
Click to show internal directories.
Click to hide internal directories.