Create & Init Project...
This commit is contained in:
36
app/service/bbq/user/internal/model/BUILD
Normal file
36
app/service/bbq/user/internal/model/BUILD
Normal file
@ -0,0 +1,36 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"model.go",
|
||||
"user.go",
|
||||
"user_face.go",
|
||||
],
|
||||
importpath = "go-common/app/service/bbq/user/internal/model",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//library/ecode:go_default_library",
|
||||
"//library/time:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
53
app/service/bbq/user/internal/model/model.go
Normal file
53
app/service/bbq/user/internal/model/model.go
Normal file
@ -0,0 +1,53 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"go-common/library/ecode"
|
||||
xtime "go-common/library/time"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
// MaxInt64 用于最大int64
|
||||
MaxInt64 = int64(^uint64(0) >> 1)
|
||||
// UserListLen 空间长度
|
||||
UserListLen = 20
|
||||
)
|
||||
|
||||
// Cache
|
||||
const (
|
||||
CacheKeyUserBase = "user_base:%d" //用户基本信息缓存key
|
||||
CacheExpireUserBase = 600
|
||||
)
|
||||
|
||||
// CursorValue 用于cursor的定位,这里可以当做通用结构使用,使用者自己根据需求定义cursor_id的含义
|
||||
type CursorValue struct {
|
||||
CursorID int64 `json:"cursor_id"`
|
||||
CursorTime xtime.Time `json:"cursor_time"`
|
||||
}
|
||||
|
||||
// ParseCursor 从cursor_prev和cursor_next,判断请求的方向,以及生成cursor
|
||||
func ParseCursor(cursorPrev string, cursorNext string) (cursor CursorValue, directionNext bool, err error) {
|
||||
// 判断是向前还是向后查询
|
||||
directionNext = true
|
||||
cursorStr := cursorNext
|
||||
if len(cursorNext) == 0 && len(cursorPrev) > 0 {
|
||||
directionNext = false
|
||||
cursorStr = cursorPrev
|
||||
}
|
||||
// 解析cursor中的cursor_id
|
||||
if len(cursorStr) != 0 {
|
||||
var cursorData = []byte(cursorStr)
|
||||
err = json.Unmarshal(cursorData, &cursor)
|
||||
if err != nil {
|
||||
err = ecode.ReqParamErr
|
||||
return
|
||||
}
|
||||
}
|
||||
// 第一次请求的时候,携带的svid=0,需要转成max传给dao层
|
||||
if directionNext && cursor.CursorID == 0 {
|
||||
cursor.CursorID = MaxInt64
|
||||
cursor.CursorTime = xtime.Time(time.Now().Unix())
|
||||
}
|
||||
return
|
||||
}
|
108
app/service/bbq/user/internal/model/user.go
Normal file
108
app/service/bbq/user/internal/model/user.go
Normal file
@ -0,0 +1,108 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
//UserTypeUp up主
|
||||
UserTypeUp = int8(1)
|
||||
//UserTypeBili b站用户
|
||||
UserTypeBili = int8(2)
|
||||
//UserTypeNew 新注册用户
|
||||
UserTypeNew = int8(3)
|
||||
//DegreeUncomp 未完成状态
|
||||
DegreeUncomp = int8(0)
|
||||
//DegreeComp 完成状态
|
||||
DegreeComp = int8(1)
|
||||
//SexMan 男
|
||||
SexMan = int8(1)
|
||||
//SexWoman 女
|
||||
SexWoman = int8(2)
|
||||
//SexAnimal 不明生物
|
||||
SexAnimal = int8(0)
|
||||
)
|
||||
|
||||
// UserListType 用于指定列表类型
|
||||
type UserListType int8
|
||||
|
||||
// UserListType的列表类型
|
||||
const (
|
||||
FollowListType UserListType = 1
|
||||
FanListType UserListType = 2
|
||||
BlackListType UserListType = 4
|
||||
|
||||
//ForbiddenStatus .
|
||||
ForbiddenStatus = 1
|
||||
//NormalStatus .
|
||||
NormalStatus = 0
|
||||
)
|
||||
|
||||
const (
|
||||
// SpaceListLen 空间长度
|
||||
SpaceListLen = 20
|
||||
// BatchUserLen 批量请求用户信息时最大数量
|
||||
BatchUserLen = 50
|
||||
// MaxBlacklistLen 黑名单最大长度
|
||||
MaxBlacklistLen = 200
|
||||
// MaxFollowListLen 关注最大数
|
||||
MaxFollowListLen = 1000
|
||||
)
|
||||
|
||||
// UserCard 主站返回的用户信息
|
||||
type UserCard struct {
|
||||
MID int64 `json:"mid"`
|
||||
Name string `json:"name"`
|
||||
Uname string `json:"uname"` // TODO: to delete
|
||||
Sex string `json:"sex"`
|
||||
Rank int32 `json:"rank"`
|
||||
Face string `json:"face"`
|
||||
Sign string `json:"sign"`
|
||||
Level int32 `json:"level"`
|
||||
VIPInfo VIPInfo `json:"vip_info"`
|
||||
}
|
||||
|
||||
// UserInfoConfig 用于请求UserInfo的时候携带的参数
|
||||
type UserInfoConfig struct {
|
||||
//needBase bool // 必须基于UserBase信息
|
||||
NeedDesc bool // 注意:desc和region_name一起,可能被降级,因为用户统计信息被认为是不重要信息
|
||||
NeedStatistic bool // 注意:可能被降级,因为用户统计信息被认为是不重要信息
|
||||
NeedFollowState bool // 注意:可能被降级,因为关注关系信息被认为是不重要信息
|
||||
}
|
||||
|
||||
//UpUserInfoRes account服务返回信息
|
||||
type UpUserInfoRes struct {
|
||||
MID int64 `json:"mid"`
|
||||
Name string `json:"name"`
|
||||
Sex string `json:"sex"`
|
||||
Face string `json:"face"`
|
||||
Sign string `json:"sign"`
|
||||
Rank int64 `json:"rank"`
|
||||
}
|
||||
|
||||
//VIPInfo .
|
||||
type VIPInfo struct {
|
||||
Type int32 `json:"type"`
|
||||
Status int32 `json:"status"`
|
||||
DueDate int64 `json:"due_date"`
|
||||
}
|
||||
|
||||
// CheckUnameSpecial 验证是否含有特殊字符
|
||||
func CheckUnameSpecial(uname string) (matched bool) {
|
||||
matched, _ = regexp.MatchString("^[A-Za-z0-9\uAC00-\uD788\u3041-\u309E\u30A1-\u30FE\u3131-\u3163\u4E00-\u9FA5\uF92C-\uFA29_-]{1,}$", uname)
|
||||
return
|
||||
}
|
||||
|
||||
//CheckUnameLength 验证长度
|
||||
func CheckUnameLength(uname string) (matched bool) {
|
||||
lu := strings.Count(uname, "") - 1
|
||||
if lu < 3 || lu > 16 {
|
||||
return false
|
||||
}
|
||||
bt := []byte(uname)
|
||||
if len(bt) < 3 || len(bt) > 30 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
15
app/service/bbq/user/internal/model/user_face.go
Normal file
15
app/service/bbq/user/internal/model/user_face.go
Normal file
@ -0,0 +1,15 @@
|
||||
package model
|
||||
|
||||
// UserFaceBFS .
|
||||
type UserFaceBFS struct {
|
||||
URL string `json:"url,omitempty"`
|
||||
FileName string `json:"file_name,omitempty"`
|
||||
Bucket string `json:"bucket,omitempty"`
|
||||
Sex float32 `json:"sex,omitempty"`
|
||||
Violent float32 `json:"violent,omitempty"`
|
||||
Blood float32 `json:"blood,omitempty"`
|
||||
Politics float32 `json:"politics,omitempty"`
|
||||
IsYellow bool `json:"is_yellow,omitempty"`
|
||||
ErrCode int32 `json:"error_code,omitempty"`
|
||||
ErrMsg string `json:"error_msg,omitempty"`
|
||||
}
|
Reference in New Issue
Block a user