Documentation ¶
Index ¶
- Constants
- func UserLogoutKey(ssid string) string
- type BasePageRequest
- type Comment
- type CommentCreateRequest
- type CommentListRequest
- type CommentRepository
- type CommentUsecase
- type CreateTagBizRequest
- type ESSearch
- type ESSync
- type Feed
- type FeedContent
- type FeedHandler
- type FeedPull
- type FeedPush
- type FeedRepository
- type FeedUsecase
- type File
- type FileListRequest
- type FileRepository
- type FileUploadsResponse
- type FileUsecase
- type GetTagsByBizRequest
- type Interaction
- type InteractionRepository
- type InteractionUseCase
- type JwtCustomClaims
- type JwtCustomRefreshClaims
- type LoginRequest
- type LoginResponse
- type LoginUsecase
- type Model
- type Post
- type PostListRequest
- type PostRepository
- type PostUsecase
- type Profile
- type RankRepository
- type RankUsecase
- type RefreshTokenRequest
- type RefreshTokenResponse
- type RefreshTokenUsecase
- type Relation
- type RelationRepository
- type RelationStat
- type RelationUsecase
- type Response
- type SearchRepository
- type SearchResult
- type SearchUsecase
- type SignupRequest
- type SignupResponse
- type SignupUsecase
- type Tag
- type TagBiz
- type TagRepository
- type TagUsecase
- type Task
- type TaskRepository
- type TaskUsecase
- type User
- type UserCollect
- type UserInteractionStat
- type UserLike
- type UserRepository
- type UserUsecase
Constants ¶
View Source
const ( FeedLikeEvent string = "feed-like" FeedPostEvent string = "feed-post" FeedFollowEvent string = "feed-follow" THRESHOLD int = 1000 // 读写扩散阈值 )
View Source
const ( FileTypeUnknown = "unknown" FileTypeImage = "image" )
View Source
const ( FileSourceKnown = "unknown" FileSourceLocal = "local" )
View Source
const ( PostTopNKey = "post_topN" PostStatusHide string = "hide" PostStatusPublish string = "publish" )
View Source
const ( Follow = true UnFollow = false )
View Source
const ( ESPostIndex = "post_index" ESUserIndex = "user_index" ESCommentIndex = "comment_index" )
View Source
const ( DefaultPage = 0 DefaultSize = 10 )
View Source
const ( XUserID = "x-user-id" UserSessionID = "user-session-id" )
View Source
const (
BizPost = "post"
)
Variables ¶
This section is empty.
Functions ¶
func UserLogoutKey ¶
Types ¶
type BasePageRequest ¶
type Comment ¶
type Comment struct { Model CommentID int64 `gorm:"primaryKey"` UserID int64 Biz string `gorm:"index:idx_biz_biz_id" binding:"required" json:"biz"` BizID int64 `gorm:"index:idx_biz_biz_id" binding:"required" json:"biz_id"` RootID sql.NullInt64 `json:"root_id" gorm:"index"` ParentID sql.NullInt64 `json:"parent_id" gorm:"index"` ParentComment *Comment `json:"parent_comment" gorm:"foreignKey:ParentID;AssociationForeignKey:CommentID;constraint:OnDelete:CASCADE"` // 简化删除操作 Content string `json:"content" binding:"required"` }
type CommentCreateRequest ¶
type CommentListRequest ¶
type CommentRepository ¶
type CommentUsecase ¶
type CreateTagBizRequest ¶
type FeedContent ¶
type FeedHandler ¶
type FeedHandler interface { CreateFeedEvent(c context.Context, t string, content FeedContent) error FindFeedEvent(c context.Context, userID, timestamp, limit int64) ([]Feed, error) }
FeedHandler 具体业务的处理逻辑 按照 type 类型来分,因为 type 天然的标记业务
type FeedPull ¶
type FeedPull struct { Model UserID int64 `gorm:"index;not null"` // 发件人 Type string Content string CreatedAt int64 `gorm:"index"` }
FeedPull 拉模型 - 读扩散
type FeedPush ¶
type FeedPush struct { Model UserID int64 `gorm:"index;not null"` // 收件人 Type string // 标记事件类型 决定Content解读方式 Content string CreatedAt int64 `gorm:"index"` }
FeedPush 推模型 - 写扩散 - 收件箱
type FeedRepository ¶
type FeedRepository interface { CreatePush(c context.Context, feed ...Feed) error CreatePull(c context.Context, feed ...Feed) error // FindPull Get from other outbox FindPull(c context.Context, userIDs []int64, timestamp, limit int64) ([]Feed, error) // FindPush Get from inbox FindPush(c context.Context, userID, timestamp, limit int64) ([]Feed, error) FindPullWithType(c context.Context, event string, userIDs []int64, timestamp, limit int64) ([]Feed, error) FindPushWithType(c context.Context, event string, userID, timestamp, limit int64) ([]Feed, error) }
type FeedUsecase ¶
type FeedUsecase interface { CreateFeedEvent(c context.Context, feed Feed) error GetFeedEventList(c context.Context, userID, timestamp, limit int64) ([]Feed, error) }
FeedUsecase 处理业务公共部分 并且负责找出 Handler 来处理业务的个性部分
type File ¶
type FileListRequest ¶
type FileListRequest struct { BasePageRequest Type string `json:"type" from:"type"` Source string `json:"source" from:"source"` }
type FileRepository ¶
type FileUploadsResponse ¶
type FileUploadsResponse struct {
Data map[string]interface{} `json:"data"` // 文件上传状态
}
type FileUsecase ¶
type GetTagsByBizRequest ¶
type Interaction ¶
type Interaction struct { Model // idx_biz select * from . where biz == // idx_bizID_biz 联合索引 (bizID区分度高) BizID int64 `gorm:"uniqueIndex:idx_interaction_bizID_biz"` //Biz string `gorm:"uniqueIndex:idx_interaction_bizID_biz"` Biz string `gorm:"type:varchar(255);uniqueIndex:idx_bizID_biz"` // MYSQL 写法 ReadCnt int LikeCnt int CollectCnt int // 3个cnt 相比较 type+cnt 在读性能友好, 每次只需要读一行 }
func (Interaction) TableName ¶
func (Interaction) TableName() string
type InteractionRepository ¶
type InteractionRepository interface { IncrReadCount(c context.Context, biz string, id int64) error BatchIncrReadCount(c context.Context, biz []string, id []int64) error Like(c context.Context, biz string, bizID, userID int64) error CancelLike(c context.Context, biz string, bizID, userID int64) error Stat(c context.Context, biz string, bizID, userID int64) (Interaction, UserInteractionStat, error) Collect(c context.Context, biz string, bizID, userID, collectionID int64) error CancelCollect(c context.Context, biz string, bizID, userID, collectionID int64) error GetByIDs(c context.Context, biz string, id []int64) (map[int64]Interaction, error) }
type InteractionUseCase ¶
type InteractionUseCase interface { IncrReadCount(c context.Context, biz string, id int64) error Like(c context.Context, biz string, bizID, userID int64) error CancelLike(c context.Context, biz string, bizID, userID int64) error Info(c context.Context, biz string, bizID, userID int64) (Interaction, UserInteractionStat, error) Collect(c context.Context, biz string, bizID, userID, collectionID int64) error CancelCollect(c context.Context, biz string, bizID, userID, collectionID int64) error }
type JwtCustomClaims ¶
type JwtCustomRefreshClaims ¶
type LoginRequest ¶
type LoginResponse ¶
type LoginUsecase ¶
type Post ¶
type Post struct { Model PostID int64 `json:"post_id,string" gorm:"primaryKey"` Title string `json:"title" form:"title" binding:"required"` Abstract string `json:"abstract" form:"abstract" binding:"required"` Content string `json:"content" form:"content" binding:"required"` AuthorID int64 `json:"author_id,string" form:"author_id"` Status string `json:"status" form:"status" binding:"required"` }
type PostListRequest ¶
type PostRepository ¶
type PostRepository interface { Create(c context.Context, post Post) error GetByID(c context.Context, id int64) (Post, error) FindMany(c context.Context, filter interface{}) ([]Post, error) // Modify List(c context.Context, filter interface{}, page, size int) ([]Post, error) FindTopNPage(c context.Context, page, size int, begin time.Time) ([]Post, error) Count(c context.Context, filter interface{}) (int64, error) }
type PostUsecase ¶
type RankRepository ¶
type RankUsecase ¶
type RefreshTokenRequest ¶
type RefreshTokenRequest struct {
RefreshToken string `form:"refresh_token" binding:"required"`
}
type RefreshTokenResponse ¶
type RefreshTokenUsecase ¶
type RefreshTokenUsecase interface { GetUserByID(c context.Context, id int64) (User, error) CreateAccessToken(user User, ssid string, secret string, expiry int) (accessToken string, err error) CreateRefreshToken(user User, ssid string, secret string, expiry int) (refreshToken string, err error) ExtractIDAndSSIDFromToken(requestToken string, secret string) (int64, string, error) }
type Relation ¶
type Relation struct { Model RelationID int64 `gorm:"primaryKey"` Followee int64 `gorm:"not null;uniqueIndex:idx_followee_follower"` // Follower 关注了 Followee Follower int64 `gorm:"not null;uniqueIndex:idx_followee_follower;index:idx_follower"` // 典型场景:某个人关注列表follower 某个人的粉丝列表followee 我都要 Status bool // true 关注 false 取消关注 }
type RelationRepository ¶
type RelationRepository interface { Follow(c context.Context, follower, followee int64) error CancelFollow(c context.Context, follower, followee int64) error GetFollower(c context.Context, follower int64, page, size int) ([]Relation, error) // 粉丝列表 GetFollowee(c context.Context, follower int64, page, size int) ([]Relation, error) // 关注者列表 Detail(c context.Context, follower, followee int64) (Relation, error) // 关注状态 FollowerCnt(c context.Context, userID int64) (int64, error) // 粉丝数 FolloweeCnt(c context.Context, userID int64) (int64, error) // 关注数 }
type RelationStat ¶
type RelationUsecase ¶
type RelationUsecase interface { Follow(c context.Context, follower, followee int64) error CancelFollow(c context.Context, follower, followee int64) error GetFollower(c context.Context, userID int64, page, size int) ([]User, int, error) // 粉丝列表 GetFollowee(c context.Context, userID int64, page, size int) ([]User, int, error) // 关注者列表 Detail(c context.Context, follower, followee int64) (Relation, error) // 关注状态 Stat(c context.Context, userID int64) (RelationStat, error) }
type Response ¶
type Response struct { Code int `json:"code"` Message string `json:"message"` Data interface{} `json:"data"` Error string `json:"error"` }
func SuccessResp ¶
func SuccessResp(data interface{}) Response
type SearchRepository ¶
type SearchResult ¶
type SearchUsecase ¶
type SignupRequest ¶
type SignupResponse ¶
type SignupUsecase ¶
type Tag ¶
type TagBiz ¶
type TagBiz struct { Model Biz string `gorm:"index:idx_tagBiz_biz_bizId"` BizID int64 `gorm:"index:idx_tagBiz_biz_bizId"` UserID int64 `gorm:"index"` TagID int64 `gorm:"index"` }
SELECT * FROM tag_biz WHERE biz = ? and biz_id = ?
type TagRepository ¶
type TagRepository interface { CreateTag(c context.Context, tag Tag) error // 用户创建Tag CreateTagBiz(c context.Context, userID int64, biz string, bizID int64, tagIDs []int64) error // 用户为某个资源加Tag GetTagsByUserID(c context.Context, userID int64) ([]Tag, error) // 查询用户所有Tag GetTagsByBiz(c context.Context, userID int64, biz string, bizID int64) ([]Tag, error) // 查询用户在某个资源上打的的Tag }
type TagUsecase ¶
type TagUsecase interface { CreateTag(c context.Context, tag Tag) error CreateTagBiz(c context.Context, userID int64, biz string, bizID int64, tagIDs []int64) error GetTagsByUserID(c context.Context, userID int64) ([]Tag, error) GetTagsByBiz(c context.Context, userID int64, biz string, bizID int64) ([]Tag, error) }
type Task ¶
type TaskRepository ¶
type TaskUsecase ¶
type User ¶
type User struct { Model UserID int64 `json:"user_id" gorm:"primaryKey"` UserName string `json:"user_name" gorm:"unique"` NickName string `json:"nick_name"` Email string `json:"email" gorm:"unique"` Password string `json:"-" gorm:"size:256"` AboutMe string `json:"about_me"` Birthday time.Time `json:"birthday" gorm:"default:null"` Phone string `json:"phone"` Region string `json:"region" gorm:"default:null"` }
type UserCollect ¶
type UserCollect struct { Model UserID int64 `gorm:"uniqueIndex:idx_userCollect_userID_bizID_biz"` BizID int64 `gorm:"uniqueIndex:idx_userCollect_userID_bizID_biz"` Biz string `gorm:"type:varchar(255);uniqueIndex:idx_userCollect_userID_bizID_biz"` CollectionID int64 `gorm:"index"` Status bool }
func (UserCollect) TableName ¶
func (UserCollect) TableName() string
type UserInteractionStat ¶
type UserLike ¶
type UserRepository ¶
type UserRepository interface { Create(c context.Context, user User) error GetByEmail(c context.Context, email string) (User, error) GetByID(c context.Context, id int64) (User, error) //UpsertAvatar(c context.Context, avatar string) error FindByUserIDs(c context.Context, userIDs []int64, page, size int) ([]User, error) InvalidToken(c context.Context, ssid string, exp time.Duration) error Update(c context.Context, id int64, user User) error }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.