refactor: 将newEventID函数移动到rabbitMQ

This commit is contained in:
Leon
2025-12-29 22:17:17 +08:00
parent 8cebfeedc7
commit bbaffe4916
2 changed files with 10 additions and 10 deletions

View File

@@ -2,6 +2,8 @@ package rabbitmq
import ( import (
"context" "context"
"crypto/rand"
"encoding/hex"
"encoding/json" "encoding/json"
"errors" "errors"
"feedsystem_video_go/internal/config" "feedsystem_video_go/internal/config"
@@ -104,3 +106,11 @@ func (r *RabbitMQ) PublishJSON(ctx context.Context, exchange string, routingKey
Body: b, Body: b,
}) })
} }
func newEventID(n int) (string, error) {
b := make([]byte, n)
if _, err := rand.Read(b); err != nil {
return "", err
}
return hex.EncodeToString(b), nil
}

View File

@@ -2,8 +2,6 @@ package rabbitmq
import ( import (
"context" "context"
"crypto/rand"
"encoding/hex"
"errors" "errors"
"time" "time"
) )
@@ -67,11 +65,3 @@ func (s *SocialMQ) publish(ctx context.Context, action, routingKey string, follo
} }
return s.PublishJSON(ctx, socialExchange, routingKey, evt) return s.PublishJSON(ctx, socialExchange, routingKey, evt)
} }
func newEventID(n int) (string, error) {
b := make([]byte, n)
if _, err := rand.Read(b); err != nil {
return "", err
}
return hex.EncodeToString(b), nil
}