Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
wang
/
golang-open-platform
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
ed7e60aa
authored
Feb 07, 2021
by
wang
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
test requests
parent
e0f1e80b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
1 deletions
controller/sku_controller.go
controller/test.go
routes/router.go
controller/sku_controller.go
View file @
ed7e60aa
...
...
@@ -46,3 +46,4 @@ func GetSkuListPrice(ctx *gin.Context) {
e
.
CheckError
(
err
)
common
.
NResponse
(
""
,
0
,
rsp
)
.
OutPut
(
ctx
)
}
controller/test.go
0 → 100644
View file @
ed7e60aa
package
controller
import
(
"github.com/gin-gonic/gin"
"golang_open_platform/pkg/common"
"golang_open_platform/pkg/gredis"
)
func
TestRequest
(
ctx
*
gin
.
Context
)
{
ctx
.
JSON
(
200
,
nil
)
}
//如果锁不存在并设置锁
func
addOnlyLock
(
key
string
){
redisWriteConn
:=
gredis
.
Conn
(
"search_w"
)
defer
redisWriteConn
.
Close
()
name
:=
"flow_lock_"
+
key
//common.PrintStdout().Printf("加锁 key:%s",name)
for
{
s
,
err
:=
redisWriteConn
.
Do
(
"SET"
,
name
,
"1"
,
"EX"
,
"10"
,
"NX"
)
//锁两秒没主动删就自动关闭(防止某个流程卡死,没执行到删除锁)
if
(
err
!=
nil
){
common
.
PrintStdout
()
.
Printf
(
"读取redis 锁 key:%d 报错"
,
key
)
}
if
(
s
!=
nil
){
//common.PrintStdout().Printf("加锁完成 key :%s",name)
break
}
}
}
//删除锁
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("解锁完成")
}
\ No newline at end of file
routes/router.go
View file @
ed7e60aa
...
...
@@ -26,6 +26,6 @@ func InitRouter() *gin.Engine {
r
.
GET
(
"GetSkuListPrice"
,
controller
.
Error_Middleware
(
"sku_query"
),
controller
.
Open_Middleware
(
"GetSkuListPrice"
),
controller
.
GetSkuListPrice
)
//
r
.
GET
(
"Test"
,
controller
.
Error_Middleware
(
"sku_query"
),
controller
.
TestRequest
)
return
r
}
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