Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Odysseus
cache
Commits
2cf1eea0
Commit
2cf1eea0
authored
Jan 26, 2024
by
vicotor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update for orm
parent
06a61d52
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
77 additions
and
65 deletions
+77
-65
cache.go
cachedata/cache.go
+1
-0
cache_test.go
cachedata/cache_test.go
+16
-5
userInfo.go
cachedata/userInfo.go
+2
-2
taskType.go
model/taskType.go
+13
-13
user.go
model/user.go
+18
-18
userLevel.go
model/userLevel.go
+17
-17
userLevelTaskType.go
model/userLevelTaskType.go
+10
-10
No files found.
cachedata/cache.go
View file @
2cf1eea0
...
@@ -34,6 +34,7 @@ func NewCacheData(ctx context.Context, options RedisConnParam, mysqlConfig model
...
@@ -34,6 +34,7 @@ func NewCacheData(ctx context.Context, options RedisConnParam, mysqlConfig model
Password
:
options
.
Password
,
Password
:
options
.
Password
,
DB
:
options
.
DbIndex
,
DB
:
options
.
DbIndex
,
PoolSize
:
100
,
PoolSize
:
100
,
Protocol
:
3
,
})
})
pathLru
,
_
:=
lru
.
New
(
10000
)
pathLru
,
_
:=
lru
.
New
(
10000
)
cache
:=
&
CacheData
{
cache
:=
&
CacheData
{
...
...
cachedata/cache_test.go
View file @
2cf1eea0
...
@@ -15,14 +15,15 @@ func newCache() *CacheData {
...
@@ -15,14 +15,15 @@ func newCache() *CacheData {
return
_cache
return
_cache
}
}
_cache
=
NewCacheData
(
context
.
Background
(),
RedisConnParam
{
_cache
=
NewCacheData
(
context
.
Background
(),
RedisConnParam
{
Addr
:
"1
27.0.0.1
:6739"
,
Addr
:
"1
92.168.1.10
:6739"
,
Password
:
"
123456
"
,
Password
:
""
,
DbIndex
:
0
,
DbIndex
:
0
,
},
model
.
DbConfig
{
},
model
.
DbConfig
{
Host
:
"1
27.0.0.
1"
,
Host
:
"1
92.168.1.21
1"
,
Port
:
3306
,
Port
:
3306
,
DbName
:
"backend"
,
DbName
:
"liuxuzhong"
,
Passwd
:
"123456"
,
Passwd
:
"12345678"
,
User
:
"root"
,
})
})
return
_cache
return
_cache
}
}
...
@@ -77,6 +78,16 @@ func TestCacheData_SetUserInfo(t *testing.T) {
...
@@ -77,6 +78,16 @@ func TestCacheData_SetUserInfo(t *testing.T) {
t
.
Log
(
user
)
t
.
Log
(
user
)
}
}
func
TestCacheData_GetUserInfo
(
t
*
testing
.
T
)
{
cache
:=
newCache
()
testUid
:=
int64
(
18
)
user
,
err
:=
cache
.
GetUserInfo
(
testUid
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
t
.
Log
(
user
)
}
func
TestCacheData_UpdateUserBalance
(
t
*
testing
.
T
)
{
func
TestCacheData_UpdateUserBalance
(
t
*
testing
.
T
)
{
cache
:=
newCache
()
cache
:=
newCache
()
testUid
:=
int64
(
1
)
testUid
:=
int64
(
1
)
...
...
cachedata/userInfo.go
View file @
2cf1eea0
...
@@ -211,7 +211,7 @@ func (c *CacheData) SetUserInfo(user *model.User) error {
...
@@ -211,7 +211,7 @@ func (c *CacheData) SetUserInfo(user *model.User) error {
func
(
c
*
CacheData
)
GetUserInfo
(
uid
int64
)
(
*
UserInfo
,
error
)
{
func
(
c
*
CacheData
)
GetUserInfo
(
uid
int64
)
(
*
UserInfo
,
error
)
{
idStr
:=
strconv
.
FormatInt
(
uid
,
10
)
idStr
:=
strconv
.
FormatInt
(
uid
,
10
)
//
get every info with pipeline
//get every info with pipeline
pip
:=
c
.
rdb
.
Pipeline
()
pip
:=
c
.
rdb
.
Pipeline
()
// get user deleted
// get user deleted
deletedCmd
:=
pip
.
Get
(
c
.
ctx
,
USER_INFO_DELETED_KEY
+
idStr
)
deletedCmd
:=
pip
.
Get
(
c
.
ctx
,
USER_INFO_DELETED_KEY
+
idStr
)
...
@@ -223,7 +223,7 @@ func (c *CacheData) GetUserInfo(uid int64) (*UserInfo, error) {
...
@@ -223,7 +223,7 @@ func (c *CacheData) GetUserInfo(uid int64) (*UserInfo, error) {
chargeCmd
:=
pip
.
Get
(
c
.
ctx
,
USER_INFO_CHARGE_KEY
+
idStr
)
chargeCmd
:=
pip
.
Get
(
c
.
ctx
,
USER_INFO_CHARGE_KEY
+
idStr
)
_
,
err
:=
pip
.
Exec
(
c
.
ctx
)
_
,
err
:=
pip
.
Exec
(
c
.
ctx
)
if
err
!=
nil
{
if
err
!=
nil
&&
err
!=
goredislib
.
Nil
{
log
.
WithError
(
err
)
.
Error
(
"failed to get user info"
)
log
.
WithError
(
err
)
.
Error
(
"failed to get user info"
)
return
nil
,
err
return
nil
,
err
}
}
...
...
model/taskType.go
View file @
2cf1eea0
...
@@ -6,19 +6,19 @@ import (
...
@@ -6,19 +6,19 @@ import (
)
)
type
TaskType
struct
{
type
TaskType
struct
{
ID
int64
`
gorm:"column:id
" db:"id" json:"id" form:"id"`
// 任务类型id
ID
int64
`
orm:"column(id)
" db:"id" json:"id" form:"id"`
// 任务类型id
Desc
string
`
gorm:"column:desc
" db:"desc" json:"desc" form:"desc"`
// 任务类型描述
Desc
string
`
orm:"column(desc)
" db:"desc" json:"desc" form:"desc"`
// 任务类型描述
Price
int64
`
gorm:"column:price
" db:"price" json:"price" form:"price"`
// 该任务类型的费用
Price
int64
`
orm:"column(price)
" db:"price" json:"price" form:"price"`
// 该任务类型的费用
Complexity
int64
`
gorm:"column:complexity
" db:"complexity" json:"complexity" form:"complexity"`
Complexity
int64
`
orm:"column(complexity)
" db:"complexity" json:"complexity" form:"complexity"`
HardwareRequire
string
`
gorm:"column:hardware_require
" db:"hardware_require" json:"hardware_require" form:"hardware_require"`
HardwareRequire
string
`
orm:"column(hardware_require)
" db:"hardware_require" json:"hardware_require" form:"hardware_require"`
ImageId
string
`
gorm:"column:image_id
" db:"image_id" json:"image_id" form:"image_id"`
ImageId
string
`
orm:"column(image_id)
" db:"image_id" json:"image_id" form:"image_id"`
ImageUrl
string
`
gorm:"column:image_url
" db:"image_url" json:"image_url" form:"image_url"`
ImageUrl
string
`
orm:"column(image_url)
" db:"image_url" json:"image_url" form:"image_url"`
Cmd
string
`
gorm:"column:cmd
" db:"cmd" json:"cmd" form:"cmd"`
Cmd
string
`
orm:"column(cmd)
" db:"cmd" json:"cmd" form:"cmd"`
Workload
int64
`
gorm:"column:workload
" db:"workload" json:"workload" form:"workload"`
Workload
int64
`
orm:"column(workload)
" db:"workload" json:"workload" form:"workload"`
ApiPath
string
`
gorm:"column:api_path
" db:"api_path" json:"api_path" form:"api_path"`
ApiPath
string
`
orm:"column(api_path)
" db:"api_path" json:"api_path" form:"api_path"`
CreatedTime
time
.
Time
`
gorm:"column:created_time
" db:"created_time" json:"created_time" form:"created_time"`
// 创建时间
CreatedTime
time
.
Time
`
orm:"column(created_time)
" db:"created_time" json:"created_time" form:"created_time"`
// 创建时间
UpdatedTime
time
.
Time
`
gorm:"column:updated_time
" db:"updated_time" json:"updated_time" form:"updated_time"`
// 更新时间
UpdatedTime
time
.
Time
`
orm:"column(updated_time)
" db:"updated_time" json:"updated_time" form:"updated_time"`
// 更新时间
Deleted
int64
`
gorm:"column:deleted
" db:"deleted" json:"deleted" form:"deleted"`
// 逻辑删除
Deleted
int64
`
orm:"column(deleted)
" db:"deleted" json:"deleted" form:"deleted"`
// 逻辑删除
}
}
func
(
TaskType
)
TableName
()
string
{
func
(
TaskType
)
TableName
()
string
{
...
...
model/user.go
View file @
2cf1eea0
...
@@ -6,24 +6,24 @@ import (
...
@@ -6,24 +6,24 @@ import (
)
)
type
User
struct
{
type
User
struct
{
ID
int64
`
gorm:"column:id
" db:"id" json:"id" form:"id"`
// 用户id
ID
int64
`
orm:"column(id)
" db:"id" json:"id" form:"id"`
// 用户id
Name
string
`
gorm:"column:name
" db:"name" json:"name" form:"name"`
// 开发者名称
Name
string
`
orm:"column(name)
" db:"name" json:"name" form:"name"`
// 开发者名称
Phone
string
`
gorm:"column:phone
" db:"phone" json:"phone" form:"phone"`
// 电话
Phone
string
`
orm:"column(phone)
" db:"phone" json:"phone" form:"phone"`
// 电话
Mail
string
`
gorm:"column:mail
" db:"mail" json:"mail" form:"mail"`
// 邮箱
Mail
string
`
orm:"column(mail)
" db:"mail" json:"mail" form:"mail"`
// 邮箱
ChainAccount
string
`
gorm:"column:chain_account
" db:"chain_account" json:"chain_account" form:"chain_account"`
// 区块链账号
ChainAccount
string
`
orm:"column(chain_account)
" db:"chain_account" json:"chain_account" form:"chain_account"`
// 区块链账号
Type
int64
`
gorm:"column:type
" db:"type" json:"type" form:"type"`
// 用户类型:\n1=自然人\n2=企业
Type
int64
`
orm:"column(type)
" db:"type" json:"type" form:"type"`
// 用户类型:\n1=自然人\n2=企业
IsAuthed
int64
`
gorm:"column:is_authed
" db:"is_authed" json:"is_authed" form:"is_authed"`
// 是否实名
IsAuthed
int64
`
orm:"column(is_authed)
" db:"is_authed" json:"is_authed" form:"is_authed"`
// 是否实名
RegisterFrom
int64
`
gorm:"column:register_from
" db:"register_from" json:"register_from" form:"register_from"`
// 注册来源,三方账号
RegisterFrom
int64
`
orm:"column(register_from)
" db:"register_from" json:"register_from" form:"register_from"`
// 注册来源,三方账号
RegisterFromDesc
string
`
gorm:"column:register_from_desc
" db:"register_from_desc" json:"register_from_desc" form:"register_from_desc"`
// 三方账户描述
RegisterFromDesc
string
`
orm:"column(register_from_desc)
" db:"register_from_desc" json:"register_from_desc" form:"register_from_desc"`
// 三方账户描述
Username
string
`
gorm:"column:username
" db:"username" json:"username" form:"username"`
// 开发者平台用户名
Username
string
`
orm:"column(username)
" db:"username" json:"username" form:"username"`
// 开发者平台用户名
Balance
int64
`
gorm:"column:balance
" db:"balance" json:"balance" form:"balance"`
// 用户账户余额
Balance
int64
`
orm:"column(balance)
" db:"balance" json:"balance" form:"balance"`
// 用户账户余额
Level
int64
`
gorm:"column:level
" db:"level" json:"level" form:"level"`
// 信用等级,决定免费调用额度
Level
int64
`
orm:"column(level)
" db:"level" json:"level" form:"level"`
// 信用等级,决定免费调用额度
CustomId
string
`
gorm:"column:custom_id
" db:"custom_id" json:"custom_id" form:"custom_id"`
// 自定义kong的id
CustomId
string
`
orm:"column(custom_id)
" db:"custom_id" json:"custom_id" form:"custom_id"`
// 自定义kong的id
VerifierId
string
`
gorm:"column:verifier_id
" db:"verifier_id" json:"verifier_id" form:"verifier_id"`
VerifierId
string
`
orm:"column(verifier_id)
" db:"verifier_id" json:"verifier_id" form:"verifier_id"`
ProfileImage
string
`
gorm:"column:profile_image
" db:"profile_image" json:"profile_image" form:"profile_image"`
ProfileImage
string
`
orm:"column(profile_image)
" db:"profile_image" json:"profile_image" form:"profile_image"`
CreatedTime
time
.
Time
`
gorm:"column:created_time
" db:"created_time" json:"created_time" form:"created_time"`
// 创建时间
CreatedTime
time
.
Time
`
orm:"column(created_time)
" db:"created_time" json:"created_time" form:"created_time"`
// 创建时间
UpdatedTime
time
.
Time
`
gorm:"column:updated_time
" db:"updated_time" json:"updated_time" form:"updated_time"`
// 更新时间
UpdatedTime
time
.
Time
`
orm:"column(updated_time)
" db:"updated_time" json:"updated_time" form:"updated_time"`
// 更新时间
Deleted
int64
`
gorm:"column:deleted
" db:"deleted" json:"deleted" form:"deleted"`
// 逻辑删除
Deleted
int64
`
orm:"column(deleted)
" db:"deleted" json:"deleted" form:"deleted"`
// 逻辑删除
}
}
func
(
User
)
TableName
()
string
{
func
(
User
)
TableName
()
string
{
...
...
model/userLevel.go
View file @
2cf1eea0
...
@@ -6,23 +6,23 @@ import (
...
@@ -6,23 +6,23 @@ import (
)
)
type
UserLevel
struct
{
type
UserLevel
struct
{
ID
int64
`
gorm:"column:id
" db:"id" json:"id" form:"id"`
// 信用等级id
ID
int64
`
orm:"column(id)
" db:"id" json:"id" form:"id"`
// 信用等级id
Level
int64
`
gorm:"column:level
" db:"level" json:"level" form:"level"`
// 等级
Level
int64
`
orm:"column(level)
" db:"level" json:"level" form:"level"`
// 等级
Desc
string
`
gorm:"column:desc
" db:"desc" json:"desc" form:"desc"`
// 描述
Desc
string
`
orm:"column(desc)
" db:"desc" json:"desc" form:"desc"`
// 描述
CreditQuota
int64
`
gorm:"column:credit_quota
" db:"credit_quota" json:"credit_quota" form:"credit_quota"`
// 该等级免费额度
CreditQuota
int64
`
orm:"column(credit_quota)
" db:"credit_quota" json:"credit_quota" form:"credit_quota"`
// 该等级免费额度
FreeCallCountDay
int64
`
gorm:"column:free_call_count_day
" db:"free_call_count_day" json:"free_call_count_day" form:"free_call_count_day"`
// 免费调用次数
FreeCallCountDay
int64
`
orm:"column(free_call_count_day)
" db:"free_call_count_day" json:"free_call_count_day" form:"free_call_count_day"`
// 免费调用次数
FreeCallCountMonth
int64
`
gorm:"column:free_call_count_month
" db:"free_call_count_month" json:"free_call_count_month" form:"free_call_count_month"`
FreeCallCountMonth
int64
`
orm:"column(free_call_count_month)
" db:"free_call_count_month" json:"free_call_count_month" form:"free_call_count_month"`
FreeCallCountYear
int64
`
gorm:"column:free_call_count_year
" db:"free_call_count_year" json:"free_call_count_year" form:"free_call_count_year"`
FreeCallCountYear
int64
`
orm:"column(free_call_count_year)
" db:"free_call_count_year" json:"free_call_count_year" form:"free_call_count_year"`
FreeCallCountTotal
int64
`
gorm:"column:free_call_count_total
" db:"free_call_count_total" json:"free_call_count_total" form:"free_call_count_total"`
FreeCallCountTotal
int64
`
orm:"column(free_call_count_total)
" db:"free_call_count_total" json:"free_call_count_total" form:"free_call_count_total"`
RateLimitSecond
int64
`
gorm:"column:rate_limit_second
" db:"rate_limit_second" json:"rate_limit_second" form:"rate_limit_second"`
// 该等级调用频率
RateLimitSecond
int64
`
orm:"column(rate_limit_second)
" db:"rate_limit_second" json:"rate_limit_second" form:"rate_limit_second"`
// 该等级调用频率
RateLimitMinute
int64
`
gorm:"column:rate_limit_minute
" db:"rate_limit_minute" json:"rate_limit_minute" form:"rate_limit_minute"`
RateLimitMinute
int64
`
orm:"column(rate_limit_minute)
" db:"rate_limit_minute" json:"rate_limit_minute" form:"rate_limit_minute"`
RateLimitHour
int64
`
gorm:"column:rate_limit_hour
" db:"rate_limit_hour" json:"rate_limit_hour" form:"rate_limit_hour"`
RateLimitHour
int64
`
orm:"column(rate_limit_hour)
" db:"rate_limit_hour" json:"rate_limit_hour" form:"rate_limit_hour"`
RateLimitDay
int64
`
gorm:"column:rate_limit_day
" db:"rate_limit_day" json:"rate_limit_day" form:"rate_limit_day"`
RateLimitDay
int64
`
orm:"column(rate_limit_day)
" db:"rate_limit_day" json:"rate_limit_day" form:"rate_limit_day"`
RateLimitMonth
int64
`
gorm:"column:rate_limit_month
" db:"rate_limit_month" json:"rate_limit_month" form:"rate_limit_month"`
RateLimitMonth
int64
`
orm:"column(rate_limit_month)
" db:"rate_limit_month" json:"rate_limit_month" form:"rate_limit_month"`
RateLimitYear
int64
`
gorm:"column:rate_limit_year
" db:"rate_limit_year" json:"rate_limit_year" form:"rate_limit_year"`
RateLimitYear
int64
`
orm:"column(rate_limit_year)
" db:"rate_limit_year" json:"rate_limit_year" form:"rate_limit_year"`
CreatedTime
time
.
Time
`
gorm:"column:created_time
" db:"created_time" json:"created_time" form:"created_time"`
// 创建时间
CreatedTime
time
.
Time
`
orm:"column(created_time)
" db:"created_time" json:"created_time" form:"created_time"`
// 创建时间
UpdatedTime
time
.
Time
`
gorm:"column:updated_time
" db:"updated_time" json:"updated_time" form:"updated_time"`
// 更新时间
UpdatedTime
time
.
Time
`
orm:"column(updated_time)
" db:"updated_time" json:"updated_time" form:"updated_time"`
// 更新时间
Deleted
int64
`
gorm:"column:deleted
" db:"deleted" json:"deleted" form:"deleted"`
// 逻辑删除
Deleted
int64
`
orm:"column(deleted)
" db:"deleted" json:"deleted" form:"deleted"`
// 逻辑删除
}
}
func
(
UserLevel
)
TableName
()
string
{
func
(
UserLevel
)
TableName
()
string
{
...
...
model/userLevelTaskType.go
View file @
2cf1eea0
...
@@ -7,16 +7,16 @@ import (
...
@@ -7,16 +7,16 @@ import (
)
)
type
UserLevelTaskType
struct
{
type
UserLevelTaskType
struct
{
ID
int64
`
gorm:"column:id
" db:"id" json:"id" form:"id"`
ID
int64
`
orm:"column(id)
" db:"id" json:"id" form:"id"`
FreeCallCountDay
int64
`
gorm:"column:free_call_count_day
" db:"free_call_count_day" json:"free_call_count_day" form:"free_call_count_day"`
FreeCallCountDay
int64
`
orm:"column(free_call_count_day)
" db:"free_call_count_day" json:"free_call_count_day" form:"free_call_count_day"`
FreeCallCountMonth
int64
`
gorm:"column:free_call_count_month
" db:"free_call_count_month" json:"free_call_count_month" form:"free_call_count_month"`
FreeCallCountMonth
int64
`
orm:"column(free_call_count_month)
" db:"free_call_count_month" json:"free_call_count_month" form:"free_call_count_month"`
FreeCallCountYear
int64
`
gorm:"column:free_call_count_year
" db:"free_call_count_year" json:"free_call_count_year" form:"free_call_count_year"`
FreeCallCountYear
int64
`
orm:"column(free_call_count_year)
" db:"free_call_count_year" json:"free_call_count_year" form:"free_call_count_year"`
FreeCallCountTotal
int64
`
gorm:"column:free_call_count_total
" db:"free_call_count_total" json:"free_call_count_total" form:"free_call_count_total"`
FreeCallCountTotal
int64
`
orm:"column(free_call_count_total)
" db:"free_call_count_total" json:"free_call_count_total" form:"free_call_count_total"`
UserLevel
int64
`
gorm:"column:user_level
" db:"user_level" json:"user_level" form:"user_level"`
UserLevel
int64
`
orm:"column(user_level)
" db:"user_level" json:"user_level" form:"user_level"`
TaskTypeId
int64
`
gorm:"column:task_type_id
" db:"task_type_id" json:"task_type_id" form:"task_type_id"`
TaskTypeId
int64
`
orm:"column(task_type_id)
" db:"task_type_id" json:"task_type_id" form:"task_type_id"`
CreatedTime
time
.
Time
`
gorm:"column:created_time
" db:"created_time" json:"created_time" form:"created_time"`
CreatedTime
time
.
Time
`
orm:"column(created_time)
" db:"created_time" json:"created_time" form:"created_time"`
UpdatedTime
time
.
Time
`
gorm:"column:updated_time
" db:"updated_time" json:"updated_time" form:"updated_time"`
UpdatedTime
time
.
Time
`
orm:"column(updated_time)
" db:"updated_time" json:"updated_time" form:"updated_time"`
Deleted
int64
`
gorm:"column:deleted
" db:"deleted" json:"deleted" form:"deleted"`
Deleted
int64
`
orm:"column(deleted)
" db:"deleted" json:"deleted" form:"deleted"`
}
}
func
(
UserLevelTaskType
)
TableName
()
string
{
func
(
UserLevelTaskType
)
TableName
()
string
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment