feat: dataReport 增加 disabled 开关,默认关闭埋点与上报

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-10-27 21:37:25 +08:00
co-authored by Claude Opus 4.7
parent d38138aeda
commit aad2f60705
10 changed files with 35 additions and 8 deletions
+11
View File
@@ -41,7 +41,15 @@ func GenerateGlobalEventID() string {
return strings.ReplaceAll(uuid.New().String(), "-", "")
}
// Enabled 当前是否允许上报:Disabled=true 或 ApiUrl 为空都视为关闭。
func Enabled() bool {
return !config.Disabled && strings.TrimSpace(config.ApiUrl) != ""
}
func AsyncReport(eventData interface{}, retryCount int) {
if !Enabled() {
return
}
// TODO 后续可改成kafka异步处理
godef.Go(func() {
// 自动重试
@@ -227,6 +235,9 @@ func JsonRawMessage(v interface{}) json.RawMessage {
// 批量上报事件
func BatchReport(ctx context.Context, data interface{}) error {
if !Enabled() {
return nil
}
apiUrl := config.ApiUrl + "/api/eventTracking/batchReport.json"
reqBody, err := json.Marshal(data)
if err != nil {