style: 统一代码格式和行尾
This commit is contained in:
@@ -4,12 +4,12 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"feedsystem_video_go/internal/config"
|
"feedsystem_video_go/internal/config"
|
||||||
"feedsystem_video_go/internal/db"
|
"feedsystem_video_go/internal/db"
|
||||||
|
mqrabbit "feedsystem_video_go/internal/middleware/rabbitmq"
|
||||||
rediscache "feedsystem_video_go/internal/middleware/redis"
|
rediscache "feedsystem_video_go/internal/middleware/redis"
|
||||||
"feedsystem_video_go/internal/observability"
|
"feedsystem_video_go/internal/observability"
|
||||||
"feedsystem_video_go/internal/social"
|
"feedsystem_video_go/internal/social"
|
||||||
"feedsystem_video_go/internal/video"
|
"feedsystem_video_go/internal/video"
|
||||||
"feedsystem_video_go/internal/worker"
|
"feedsystem_video_go/internal/worker"
|
||||||
mqrabbit "feedsystem_video_go/internal/middleware/rabbitmq"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
|||||||
@@ -71,9 +71,9 @@ type GetProfileRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GetProfileResponse struct {
|
type GetProfileResponse struct {
|
||||||
Account FindByIDResponse `json:"account"`
|
Account FindByIDResponse `json:"account"`
|
||||||
VideoCount int64 `json:"video_count"`
|
VideoCount int64 `json:"video_count"`
|
||||||
TotalLikes int64 `json:"total_likes"`
|
TotalLikes int64 `json:"total_likes"`
|
||||||
FollowerCount int64 `json:"follower_count"`
|
FollowerCount int64 `json:"follower_count"`
|
||||||
VloggerCount int64 `json:"vlogger_count"`
|
VloggerCount int64 `json:"vlogger_count"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package feed
|
package feed
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"feedsystem_video_go/internal/middleware/jwt"
|
|
||||||
"feedsystem_video_go/internal/apierror"
|
"feedsystem_video_go/internal/apierror"
|
||||||
|
"feedsystem_video_go/internal/middleware/jwt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|||||||
@@ -6,16 +6,16 @@ import (
|
|||||||
"feedsystem_video_go/internal/feed"
|
"feedsystem_video_go/internal/feed"
|
||||||
"feedsystem_video_go/internal/message"
|
"feedsystem_video_go/internal/message"
|
||||||
"feedsystem_video_go/internal/middleware/jwt"
|
"feedsystem_video_go/internal/middleware/jwt"
|
||||||
"feedsystem_video_go/internal/middleware/ratelimit"
|
|
||||||
"feedsystem_video_go/internal/middleware/rabbitmq"
|
"feedsystem_video_go/internal/middleware/rabbitmq"
|
||||||
|
"feedsystem_video_go/internal/middleware/ratelimit"
|
||||||
rediscache "feedsystem_video_go/internal/middleware/redis"
|
rediscache "feedsystem_video_go/internal/middleware/redis"
|
||||||
"feedsystem_video_go/internal/social"
|
"feedsystem_video_go/internal/social"
|
||||||
"feedsystem_video_go/internal/video"
|
"feedsystem_video_go/internal/video"
|
||||||
"feedsystem_video_go/internal/worker"
|
"feedsystem_video_go/internal/worker"
|
||||||
"log"
|
|
||||||
"time"
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"log"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SetRouter(db *gorm.DB, cache *rediscache.Client, rmq *rabbitmq.RabbitMQ) *gin.Engine {
|
func SetRouter(db *gorm.DB, cache *rediscache.Client, rmq *rabbitmq.RabbitMQ) *gin.Engine {
|
||||||
@@ -157,7 +157,7 @@ func SetRouter(db *gorm.DB, cache *rediscache.Client, rmq *rabbitmq.RabbitMQ) *g
|
|||||||
vloggerCount, _ := socialRepository.CountVloggers(c.Request.Context(), req.AccountID)
|
vloggerCount, _ := socialRepository.CountVloggers(c.Request.Context(), req.AccountID)
|
||||||
|
|
||||||
c.JSON(200, account.GetProfileResponse{
|
c.JSON(200, account.GetProfileResponse{
|
||||||
Account: account.FindByIDResponse{ID: acc.ID, Username: acc.Username, AvatarURL: acc.AvatarURL, Bio: acc.Bio},
|
Account: account.FindByIDResponse{ID: acc.ID, Username: acc.Username, AvatarURL: acc.AvatarURL, Bio: acc.Bio},
|
||||||
VideoCount: videoCount, TotalLikes: totalLikes,
|
VideoCount: videoCount, TotalLikes: totalLikes,
|
||||||
FollowerCount: followerCount, VloggerCount: vloggerCount,
|
FollowerCount: followerCount, VloggerCount: vloggerCount,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ type Service struct{ repo *Repository }
|
|||||||
type Handler struct{ service *Service }
|
type Handler struct{ service *Service }
|
||||||
|
|
||||||
func NewRepository(db *gorm.DB) *Repository { return &Repository{db: db} }
|
func NewRepository(db *gorm.DB) *Repository { return &Repository{db: db} }
|
||||||
func NewService(repo *Repository) *Service { return &Service{repo: repo} }
|
func NewService(repo *Repository) *Service { return &Service{repo: repo} }
|
||||||
func NewHandler(service *Service) *Handler { return &Handler{service: service} }
|
func NewHandler(service *Service) *Handler { return &Handler{service: service} }
|
||||||
|
|
||||||
func (r *Repository) AutoMigrate(ctx context.Context) error {
|
func (r *Repository) AutoMigrate(ctx context.Context) error {
|
||||||
return r.db.WithContext(ctx).AutoMigrate(&Message{})
|
return r.db.WithContext(ctx).AutoMigrate(&Message{})
|
||||||
|
|||||||
@@ -68,4 +68,3 @@ func (c *CommentMQ) publish(ctx context.Context, action, routingKey string, evt
|
|||||||
evt.OccurredAt = time.Now().UTC()
|
evt.OccurredAt = time.Now().UTC()
|
||||||
return c.PublishJSON(ctx, commentExchange, routingKey, evt)
|
return c.PublishJSON(ctx, commentExchange, routingKey, evt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,4 +54,3 @@ func (p *PopularityMQ) Update(ctx context.Context, videoID uint, change int64) e
|
|||||||
}
|
}
|
||||||
return p.PublishJSON(ctx, popularityExchange, popularityUpdateRK, event)
|
return p.PublishJSON(ctx, popularityExchange, popularityUpdateRK, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package ratelimit
|
package ratelimit
|
||||||
|
|
||||||
import (
|
import (
|
||||||
rediscache "feedsystem_video_go/internal/middleware/redis"
|
|
||||||
jwt "feedsystem_video_go/internal/middleware/jwt"
|
jwt "feedsystem_video_go/internal/middleware/jwt"
|
||||||
|
rediscache "feedsystem_video_go/internal/middleware/redis"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"strconv"
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type KeyFunc func(*gin.Context) (string, bool)
|
type KeyFunc func(*gin.Context) (string, bool)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewPprofMux(t *testing.T) {
|
func TestNewPprofMux(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package video
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"feedsystem_video_go/internal/apierror"
|
||||||
"feedsystem_video_go/internal/middleware/rabbitmq"
|
"feedsystem_video_go/internal/middleware/rabbitmq"
|
||||||
rediscache "feedsystem_video_go/internal/middleware/redis"
|
rediscache "feedsystem_video_go/internal/middleware/redis"
|
||||||
"feedsystem_video_go/internal/apierror"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package video
|
package video
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"feedsystem_video_go/internal/middleware/jwt"
|
|
||||||
"feedsystem_video_go/internal/apierror"
|
"feedsystem_video_go/internal/apierror"
|
||||||
|
"feedsystem_video_go/internal/middleware/jwt"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"feedsystem_video_go/internal/apierror"
|
||||||
"feedsystem_video_go/internal/middleware/rabbitmq"
|
"feedsystem_video_go/internal/middleware/rabbitmq"
|
||||||
rediscache "feedsystem_video_go/internal/middleware/redis"
|
rediscache "feedsystem_video_go/internal/middleware/redis"
|
||||||
"feedsystem_video_go/internal/apierror"
|
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -125,4 +125,3 @@ func (w *CommentWorker) applyDelete(ctx context.Context, evt *rabbitmq.CommentEv
|
|||||||
}
|
}
|
||||||
return w.comments.DeleteComment(ctx, c)
|
return w.comments.DeleteComment(ctx, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,16 +6,16 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"feedsystem_video_go/internal/middleware/rabbitmq"
|
"feedsystem_video_go/internal/middleware/rabbitmq"
|
||||||
"feedsystem_video_go/internal/video"
|
"feedsystem_video_go/internal/video"
|
||||||
"log"
|
|
||||||
amqp "github.com/rabbitmq/amqp091-go"
|
amqp "github.com/rabbitmq/amqp091-go"
|
||||||
|
"log"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LikeWorker struct {
|
type LikeWorker struct {
|
||||||
ch *amqp.Channel
|
ch *amqp.Channel
|
||||||
likes *video.LikeRepository
|
likes *video.LikeRepository
|
||||||
videos *video.VideoRepository
|
videos *video.VideoRepository
|
||||||
queue string
|
queue string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLikeWorker(ch *amqp.Channel, likes *video.LikeRepository, videos *video.VideoRepository, queue string) *LikeWorker {
|
func NewLikeWorker(ch *amqp.Channel, likes *video.LikeRepository, videos *video.VideoRepository, queue string) *LikeWorker {
|
||||||
|
|||||||
@@ -13,21 +13,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Notification struct {
|
type Notification struct {
|
||||||
ID uint `gorm:"primaryKey" json:"id"`
|
ID uint `gorm:"primaryKey" json:"id"`
|
||||||
RecipientID uint `gorm:"index;not null" json:"recipient_id"`
|
RecipientID uint `gorm:"index;not null" json:"recipient_id"`
|
||||||
SenderID uint `gorm:"not null" json:"sender_id"`
|
SenderID uint `gorm:"not null" json:"sender_id"`
|
||||||
Type string `gorm:"type:varchar(50);not null" json:"type"`
|
Type string `gorm:"type:varchar(50);not null" json:"type"`
|
||||||
TargetID uint `json:"target_id"`
|
TargetID uint `json:"target_id"`
|
||||||
Content string `gorm:"type:varchar(255)" json:"content"`
|
Content string `gorm:"type:varchar(255)" json:"content"`
|
||||||
IsRead bool `gorm:"default:false" json:"is_read"`
|
IsRead bool `gorm:"default:false" json:"is_read"`
|
||||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type NotificationWorker struct {
|
type NotificationWorker struct {
|
||||||
ch *amqp.Channel
|
ch *amqp.Channel
|
||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
queue string
|
queue string
|
||||||
hub NotificationHub
|
hub NotificationHub
|
||||||
}
|
}
|
||||||
|
|
||||||
type NotificationHub interface {
|
type NotificationHub interface {
|
||||||
@@ -96,7 +96,10 @@ func (w *NotificationWorker) process(ctx context.Context, d amqp.Delivery) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
var authorID uint
|
var authorID uint
|
||||||
w.db.WithContext(ctx).Model(&struct{ ID uint; AuthorID uint }{}).Table("videos").Where("id = ?", evt.VideoID).Select("author_id").Scan(&authorID)
|
w.db.WithContext(ctx).Model(&struct {
|
||||||
|
ID uint
|
||||||
|
AuthorID uint
|
||||||
|
}{}).Table("videos").Where("id = ?", evt.VideoID).Select("author_id").Scan(&authorID)
|
||||||
if authorID == 0 || authorID == evt.UserID {
|
if authorID == 0 || authorID == evt.UserID {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -111,7 +114,10 @@ func (w *NotificationWorker) process(ctx context.Context, d amqp.Delivery) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
var authorID uint
|
var authorID uint
|
||||||
w.db.WithContext(ctx).Model(&struct{ ID uint; AuthorID uint }{}).Table("videos").Where("id = ?", evt.VideoID).Select("author_id").Scan(&authorID)
|
w.db.WithContext(ctx).Model(&struct {
|
||||||
|
ID uint
|
||||||
|
AuthorID uint
|
||||||
|
}{}).Table("videos").Where("id = ?", evt.VideoID).Select("author_id").Scan(&authorID)
|
||||||
if authorID == 0 || authorID == evt.AuthorID {
|
if authorID == 0 || authorID == evt.AuthorID {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,4 +82,3 @@ func (w *PopularityWorker) process(ctx context.Context, body []byte) error {
|
|||||||
video.UpdatePopularityCache(ctx, w.cache, evt.VideoID, evt.Change)
|
video.UpdatePopularityCache(ctx, w.cache, evt.VideoID, evt.Change)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type SSEHub struct {
|
type SSEHub struct {
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
clients map[uint][]chan *Notification
|
clients map[uint][]chan *Notification
|
||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSSEHub(db *gorm.DB) *SSEHub {
|
func NewSSEHub(db *gorm.DB) *SSEHub {
|
||||||
|
|||||||
Reference in New Issue
Block a user