Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
wang
/
go_supplier_task
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c9688c9a
authored
Feb 22, 2021
by
wang
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
删除test文件
parent
d2cb5033
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
1 additions
and
117 deletions
.gitignore
controller/sku_controller.go
controller/test.go
.gitignore
View file @
c9688c9a
...
@@ -24,4 +24,4 @@ cmd.exe~
...
@@ -24,4 +24,4 @@ cmd.exe~
/controller/test.lua
/controller/test.lua
/open/redisLock
/open/redisLock
/tests
/tests
/controller/test.go
controller/sku_controller.go
View file @
c9688c9a
package
controller
package
controller
import
(
import
(
"fmt"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"github.com/gogf/gf/util/gconv"
"github.com/gogf/gf/util/gconv"
"golang_open_platform/model"
"golang_open_platform/model"
...
@@ -60,7 +59,6 @@ func GetClassList(ctx *gin.Context) {
...
@@ -60,7 +59,6 @@ func GetClassList(ctx *gin.Context) {
common
.
NResponse
(
"parent_id 必填"
,
open
.
PARAM1
,
nil
)
.
OutPut
(
ctx
)
common
.
NResponse
(
"parent_id 必填"
,
open
.
PARAM1
,
nil
)
.
OutPut
(
ctx
)
return
return
}
}
fmt
.
Printf
(
parent_id
)
rsp
,
err
:=
service
.
NewClassService
()
.
GetClassList
(
gconv
.
Int
(
parent_id
))
rsp
,
err
:=
service
.
NewClassService
()
.
GetClassList
(
gconv
.
Int
(
parent_id
))
e
.
CheckError
(
err
)
e
.
CheckError
(
err
)
common
.
NResponse
(
""
,
0
,
rsp
)
.
OutPut
(
ctx
)
common
.
NResponse
(
""
,
0
,
rsp
)
.
OutPut
(
ctx
)
...
...
controller/test.go
deleted
100644 → 0
View file @
d2cb5033
package
controller
import
(
"fmt"
"github.com/gin-gonic/gin"
"github.com/gomodule/redigo/redis"
"golang_open_platform/pkg/common"
"golang_open_platform/pkg/e"
"golang_open_platform/pkg/gredis"
)
func
TestRequest
(
ctx
*
gin
.
Context
)
{
ctx
.
JSON
(
200
,
nil
)
}
func
LuaTest
()
{
}
func
LockTest
(
ctx
*
gin
.
Context
)
{
defer
delOnlyLock
(
"test_lock"
)
err
:=
addOnlyLock
(
"test_lock"
)
if
(
err
!=
nil
){
common
.
PrintStdout
()
.
Printf
(
"加锁失败"
)
return
}
num
,
err
:=
getRedisFlowNum
(
"abc"
)
fmt
.
Println
(
num
)
if
(
err
!=
nil
){
common
.
PrintStdout
()
.
Printf
(
err
.
Error
())
}
if
(
num
>=
2100
){
common
.
PrintStdout
()
.
Printf
(
"频率限制"
)
ctx
.
JSON
(
200
,
"频率限制"
)
return
}
num
,
err
=
incrRedisFlowNum
(
"abc"
)
if
(
err
!=
nil
){
common
.
PrintStdout
()
.
Printf
(
"新增报错"
)
}
common
.
PrintStdout
()
.
Printf
(
"新增后的值"
+
string
(
num
))
ctx
.
JSON
(
200
,
"锁测试"
)
}
func
incrRedisFlowNum
(
key
string
)
(
num
int
,
err
error
){
redisWriteConn
:=
gredis
.
Conn
(
"search_w"
)
defer
redisWriteConn
.
Close
()
num
,
err
=
redis
.
Int
(
redisWriteConn
.
Do
(
"INCR"
,
key
))
if
(
err
!=
nil
){
common
.
PrintStdout
()
.
Printf
(
"INCR redis "
+
key
+
"错误"
)
//return 0,e.NewApiError("service error",FLOWERR1)
}
return
num
,
nil
}
func
abc
()
{
redisWriteConn
:=
gredis
.
Conn
(
"search_w"
)
defer
redisWriteConn
.
Close
()
}
//如果锁不存在并设置锁
func
addOnlyLock
(
key
string
)
error
{
redisWriteConn
:=
gredis
.
Conn
(
"search_w"
)
defer
redisWriteConn
.
Close
()
name
:=
"flow_lock_"
+
key
//common.PrintStdout().Printf("加锁 key:%s",name)
//for{
r
,
err
:=
redisWriteConn
.
Do
(
"SET"
,
name
,
"1"
,
"EX"
,
"100"
,
"NX"
)
//锁两秒没主动删就自动关闭(防止某个流程卡死,没执行到删除锁)
if
(
err
!=
nil
){
common
.
PrintStdout
()
.
Printf
(
"读取redis 锁 key:%d 报错"
,
key
)
}
if
(
r
!=
nil
){
return
nil
}
//}
incrRedisFlowNum
(
"err_num"
)
//common.PrintStdout().Printf("没读到")
return
fmt
.
Errorf
(
"请重试"
)
}
//删除锁
func
delOnlyLock
(
key
string
){
redisWriteConn
:=
gredis
.
Conn
(
"search_w"
)
defer
redisWriteConn
.
Close
()
name
:=
"flow_lock_"
+
key
_
,
err
:=
redisWriteConn
.
Do
(
"DEL"
,
name
)
if
(
err
!=
nil
){
println
(
err
.
Error
())
}
common
.
PrintStdout
()
.
Printf
(
"解锁完成"
)
}
func
getRedisFlowNum
(
key
string
)
(
num
int
,
err
error
){
redisReadConn
:=
gredis
.
Conn
(
"search_r"
)
defer
redisReadConn
.
Close
()
num
,
err
=
redis
.
Int
(
redisReadConn
.
Do
(
"Get"
,
key
))
if
(
err
!=
nil
&&
err
!=
redis
.
ErrNil
){
common
.
PrintStdout
()
.
Printf
(
"读取redis "
+
key
+
"错误"
+
err
.
Error
())
return
0
,
e
.
NewApiError
(
"service error"
,
80000
)
}
return
num
,
nil
}
\ No newline at end of file
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