Documentation
¶
Index ¶
- Constants
- Variables
- func UserLogoutKey(ssid string) string
- type BasePageRequest
- type CodeRepository
- type CodeUsecase
- type Comment
- type CommentCreateRequest
- type CommentInfo
- 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 GetAdminTokenRequest
- type GetAdminTokenResponse
- type GetFeedEventListReq
- type GetTagsByBizRequest
- type GetUserTokenRequest
- type GetUserTokenResponse
- type Interaction
- type InteractionRepository
- type InteractionUseCase
- type JwtCustomClaims
- type JwtCustomRefreshClaims
- type LoginByPhoneReq
- type LoginBySmsReq
- type LoginReq
- type LoginResp
- type Model
- type Post
- type PostDeleteRequest
- type PostInfoResponse
- type PostListRequest
- type PostRepository
- type PostResponse
- type PostSearchRequest
- type PostUsecase
- type Profile
- type RankRepository
- type RankUsecase
- type RefreshTokenRequest
- type RefreshTokenResponse
- type RefreshTokenUsecase
- type Relation
- type RelationRepository
- type RelationStat
- type RelationUsecase
- type ResetPasswordReq
- type Response
- type SearchRepository
- type SearchResult
- type SearchUsecase
- type SendSMSCodeReq
- type SignupReq
- type SignupResp
- type SortRule
- type Sync2OpenIMUsecase
- type Sync2OpenIMUser
- type SyncUserRequest
- type SyncUserResponse
- type Tag
- type TagBiz
- type TagRepository
- type TagUsecase
- type Task
- type TaskRepository
- type TaskUsecase
- type User
- type UserBatchProfileReq
- type UserCollect
- type UserInteractionStat
- type UserLike
- type UserRepository
- type UserSearchReq
- type UserUsecase
Constants ¶
View Source
const ( FeedLikeEvent string = "feed-like" FeedUnlikeEvent string = "feed-unlike" FeedCommentEvent string = "feed-comment" FeedReplyEvent string = "feed-reply" FeedCollectEvent string = "feed-collect" FeedUncollectEvent string = "feed-uncollect" FeedPostEvent string = "feed-post" FeedFollowEvent string = "feed-follow" FeedUnfollowEvent string = "feed-unfollow" FeedUnkonwnEvent string = "feed-unknown" THRESHOLD int = 1000 // 读写扩散阈值 )
View Source
const ( FileTypeUnknown = "unknown" FileTypeImage = "image" FileSourceKnown = "unknown" FileSourceLocal = "local" FileSourceMinio = "minio" FileBucket = "go-backend" )
View Source
const ( DefaultOpenIMDomain = "http://localhost:10002" DefaultOpenIMSecret = "openIM123" DefaultOpenIMUserID = "imAdmin" Sync2OpenIMOpRegister = "register" Sync2OpenIMOpEdit = "edit" )
View Source
const ( PostTopNKey = "post_topN" PostStatusHide string = "hide" PostStatusPublish string = "publish" PromptOfPostAbstract = "" /* 167-byte string literal not displayed */ )
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 DefaultUserPassword = "root" DefaultUserNamePrefix = "user" )
View Source
const ( XUserID = "x-user-id" UserSessionID = "user-session-id" BizUserLogin = "login" )
View Source
const (
BizComment = "comment"
)
View Source
const (
BizPost = "post"
)
Variables ¶
View Source
var ( ErrCodeSendTooFrequently = errors.New("code send too frequently") ErrCodeVerifyTooFrequently = errors.New("code verify too frequently") ErrCodeInvalid = errors.New("code invalid") )
View Source
var ( ErrBusy = errors.New("系统繁忙") ErrSystemError = errors.New("系统错误") ErrUnKnowError = errors.New("未知错误") ErrBadParams = errors.New("参数错误") ErrRateLimit = errors.New("请求过于频繁") )
View Source
var (
ErrSync2OpenIMOpNotFound = errors.New("synchronous methods do not exist, only registration and editing are supported")
)
Functions ¶
func UserLogoutKey ¶
Types ¶
type BasePageRequest ¶
type CodeRepository ¶
type CodeUsecase ¶
type Comment ¶
type Comment struct { Model CommentID int64 `gorm:"primaryKey" json:"comment_id,string"` ParentCommentID int64 `gorm:"index" json:"parent_comment_id,string"` // 一级评论的 parent_comment_id = 0 其他评论的 parent_comment_id = 一级评论的 comment_id Content string `gorm:"not null" json:"content"` UserID int64 `gorm:"not null" json:"user_id,string"` ToUserID int64 `json:"to_user_id,string"` // 回复某人的时候,to_user_id = 被回复的用户的 user_id 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,string"` LikeCount int `json:"like_count"` // 点赞数 ReplyCount int `json:"reply_count"` // 回复数 }
帖子 一级评论 某个用户回复该帖子 commentid userid content 二级评论 在某个一级评论下回复 commentid userid content parentid(一级评论的commentid) 二级评论 在某个一级评论下回复某人 commentid userid content parentid(一级评论的commentid) to_userid
type CommentCreateRequest ¶
type CommentCreateRequest struct { Biz string `json:"biz" binding:"required"` BizID string `json:"biz_id" binding:"required"` Content string `json:"content" binding:"required"` ParentID string `json:"parent_id"` // default 0 表示回复的是帖子 ToUserID string `json:"to_user_id"` // default 0 表示回复的是帖子 or 一级评论 }
type CommentInfo ¶
type CommentListRequest ¶
type CommentRepository ¶
type CommentRepository interface { Create(c context.Context, comment *Comment) error Delete(c context.Context, id int64) error // 删除本节点和其对应的子节点 Find(c context.Context, biz string, bizID, parentID, minID int64, limit int) ([]Comment, int, error) // 查找一级评论则 parentID=0 Count(c context.Context, biz string, bizID int64) (int, error) }
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 GetAdminTokenRequest ¶
type GetAdminTokenResponse ¶
type GetFeedEventListReq ¶
type GetTagsByBizRequest ¶
type GetUserTokenRequest ¶
type GetUserTokenResponse ¶
type Interaction ¶
type Interaction struct { Model // idx_biz select * from . where biz == // idx_bizID_biz 联合索引 (bizID区分度高) BizID int64 `json:"biz_id" gorm:"uniqueIndex:idx_interaction_bizID_biz"` //Biz string `gorm:"uniqueIndex:idx_interaction_bizID_biz"` Biz string `json:"biz" gorm:"type:varchar(255);uniqueIndex:idx_interaction_bizID_biz"` // MYSQL 写法 ReadCnt int `json:"read_cnt"` LikeCnt int `json:"like_cnt"` CollectCnt int `json:"collect_cnt"` // 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 LoginByPhoneReq ¶
type LoginBySmsReq ¶
type Post ¶
type Post struct { Model PostID int64 `json:"post_id,string" gorm:"primaryKey"` Title string `json:"title" form:"title"` Abstract string `json:"abstract" form:"abstract"` Content string `json:"content" form:"content"` AuthorID int64 `json:"author_id,string" form:"author_id"` Status string `json:"status" form:"status" binding:"required"` Images string `json:"images" form:"images"` }
type PostDeleteRequest ¶
type PostDeleteRequest struct {
PostID int64 `json:"post_id,string" form:"post_id"`
}
type PostInfoResponse ¶
type PostInfoResponse struct { Post PostResponse `json:"post"` Interaction Interaction `json:"interaction"` Stat UserInteractionStat `json:"stat"` CommentCount int `json:"comment_count"` }
type PostListRequest ¶
type PostRepository ¶
type PostRepository interface { Create(c context.Context, post *Post) error Delete(c context.Context, postID int64) 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) ListByLastID(c context.Context, filter interface{}, size int, lastID int64) ([]Post, error) FindTopNPage(c context.Context, page, size int, begin time.Time) ([]Post, error) Count(c context.Context, filter interface{}) (int64, error) Update(c context.Context, id int64, post *Post) error Search(c context.Context, keyword string, page, size int, rule []SortRule) ([]Post, int, error) }
type PostResponse ¶
type PostResponse struct { Model PostID int64 `json:"post_id,string"` Title string `json:"title"` Abstract string `json:"abstract"` Content string `json:"content" ` // AuthorID int64 `json:"author_id,string" form:"author_id"` Status string `json:"status"` Author Profile `json:"author"` Images []string `json:"images"` }
type PostSearchRequest ¶
type PostUsecase ¶
type PostUsecase interface { Create(c context.Context, post *Post) error Delete(c context.Context, postID int64) error List(c context.Context, filter interface{}, page, size int) ([]Post, int64, error) ListByLastID(c context.Context, filter interface{}, size int, lastID int64) ([]Post, int64, error) Info(c context.Context, postID int64) (Post, error) TopN(c context.Context) ([]Post, error) Count(c context.Context, filter interface{}) (int64, error) Search(c context.Context, keyword string, page, size int, rule []SortRule) ([]Post, int, error) }
type Profile ¶
type Profile struct { UserID int64 `json:"user_id,string"` UserName string `json:"user_name"` NickName string `json:"nick_name"` Email string `json:"email"` AboutMe string `json:"about_me"` Birthday time.Time `json:"birthday"` Avatar string `json:"avatar"` RelationStat RelationStat `json:"relation_stat"` PostCnt int64 `json:"post_cnt"` CreatedAt time.Time `json:"created_at"` }
type RankRepository ¶
type RankUsecase ¶
type RefreshTokenRequest ¶
type RefreshTokenRequest struct {
RefreshToken string `form:"refresh_token" json:"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) bool // 关注状态 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) bool // 关注状态 Stat(c context.Context, userID int64) (RelationStat, error) }
type ResetPasswordReq ¶
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 SendSMSCodeReq ¶
type SendSMSCodeReq struct {
Phone string `form:"phone" json:"phone" binding:"required"`
}
type SignupResp ¶
type Sync2OpenIMUsecase ¶
type Sync2OpenIMUser ¶
type SyncUserRequest ¶
type SyncUserRequest struct {
Users []Sync2OpenIMUser `json:"users"`
}
type SyncUserResponse ¶
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,string" gorm:"primaryKey"` UserName string `json:"user_name" gorm:"unique"` NickName string `json:"nick_name" gorm:"size:256"` Email string `json:"email" gorm:"default:null;unique"` Password string `json:"-" gorm:"size:256"` AboutMe string `json:"about_me" gorm:"size:256"` Birthday time.Time `json:"birthday" gorm:"default:null"` Phone string `json:"phone" gorm:"default:null;unique"` Region string `json:"region" gorm:"default:null"` Avatar string `json:"avatar" gorm:"size:1024"` }
type UserBatchProfileReq ¶
type UserBatchProfileReq struct {
UserIDs []string `form:"user_ids" json:"user_ids"`
}
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) GetByPhone(c context.Context, phone string) (User, 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 Search(c context.Context, keyword string, page, size int) ([]User, int, error) }
type UserSearchReq ¶
type UserUsecase ¶
type UserUsecase interface { GetProfileByID(c context.Context, userID int64) (Profile, error) BatchGetProfileByID(c context.Context, userIDs []int64) ([]Profile, error) UpdateProfile(c context.Context, userID int64, user *User) error Logout(c context.Context, SSID string, tokenExpiry time.Duration) error GetUserByEmail(c context.Context, email string) (User, error) GetUserByUserID(c context.Context, userID 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) Create(c context.Context, user *User) error GetUserByPhone(c context.Context, phone string) (User, error) Search(c context.Context, keyword string, page, size int) ([]User, int, error) }
Source Files
¶
Click to show internal directories.
Click to hide internal directories.