Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-user
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
chenweijian
hilo-user
Commits
40ccfdb2
Commit
40ccfdb2
authored
Jul 07, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/encrypt' into 'master'
Feature/encrypt See merge request
!13
parents
a078098c
96bc98cc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
8 deletions
+34
-8
response.go
resp/response.go
+19
-6
middleHandle.go
route/middleHandle.go
+13
-0
router.go
route/router.go
+2
-2
No files found.
resp/response.go
View file @
40ccfdb2
...
@@ -3,6 +3,7 @@ package resp
...
@@ -3,6 +3,7 @@ package resp
import
(
import
(
"encoding/json"
"encoding/json"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/utils"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"hilo-user/myerr"
"hilo-user/myerr"
"hilo-user/req"
"hilo-user/req"
...
@@ -15,6 +16,7 @@ type Response struct {
...
@@ -15,6 +16,7 @@ type Response struct {
MessageData
interface
{}
`json:"messageData"`
// 消息详情
MessageData
interface
{}
`json:"messageData"`
// 消息详情
OperationMessage
interface
{}
`json:"operationMessage"`
// 操作消息
OperationMessage
interface
{}
`json:"operationMessage"`
// 操作消息
Data
interface
{}
`json:"data"`
// 数据
Data
interface
{}
`json:"data"`
// 数据
Edata
interface
{}
`json:"edata"`
// 加密数据
}
}
type
GameResponse
struct
{
type
GameResponse
struct
{
...
@@ -36,7 +38,12 @@ func ResponseOk(c *gin.Context, data interface{}) {
...
@@ -36,7 +38,12 @@ func ResponseOk(c *gin.Context, data interface{}) {
Code
:
myerr
.
GetSuccessCode
(),
Code
:
myerr
.
GetSuccessCode
(),
Message
:
myerr
.
GetSuccessMsg
(),
Message
:
myerr
.
GetSuccessMsg
(),
OperationMessage
:
myerr
.
GetSuccessMsg
(),
OperationMessage
:
myerr
.
GetSuccessMsg
(),
Data
:
data
,
}
if
_
,
ok
:=
c
.
Get
(
mycontext
.
InnerEncrypt
);
ok
{
//response.Edata = utils.EncryptionData(data, []byte("484194d4d0f968a7"))
response
.
Edata
=
utils
.
EncryptionData
(
data
,
[]
byte
(
"hilo!@#$%^&*()_+"
))
}
else
{
response
.
Data
=
data
}
}
printResponseBody
(
c
,
&
response
)
printResponseBody
(
c
,
&
response
)
...
@@ -50,15 +57,21 @@ func ResponsePageBaseOk(c *gin.Context, data interface{}, nextPageIndex int, has
...
@@ -50,15 +57,21 @@ func ResponsePageBaseOk(c *gin.Context, data interface{}, nextPageIndex int, has
if
data
==
nil
{
if
data
==
nil
{
data
=
make
([]
interface
{},
0
)
data
=
make
([]
interface
{},
0
)
}
}
pageData
:=
req
.
PageRespBase
{
NextPageIndex
:
nextPageIndex
,
HasNextPage
:
hasNextPage
,
Data
:
data
,
}
response
:=
Response
{
response
:=
Response
{
Code
:
myerr
.
GetSuccessCode
(),
Code
:
myerr
.
GetSuccessCode
(),
Message
:
myerr
.
GetSuccessMsg
(),
Message
:
myerr
.
GetSuccessMsg
(),
OperationMessage
:
myerr
.
GetSuccessMsg
(),
OperationMessage
:
myerr
.
GetSuccessMsg
(),
Data
:
req
.
PageRespBase
{
}
NextPageIndex
:
nextPageIndex
,
if
_
,
ok
:=
c
.
Get
(
mycontext
.
InnerEncrypt
);
ok
{
HasNextPage
:
hasNextPage
,
//response.Edata = utils.EncryptionData(data, []byte("484194d4d0f968a7"))
Data
:
data
,
response
.
Edata
=
utils
.
EncryptionData
(
pageData
,
[]
byte
(
"hilo!@#$%^&*()_+"
))
},
}
else
{
response
.
Data
=
pageData
}
}
c
.
JSON
(
http
.
StatusOK
,
response
)
c
.
JSON
(
http
.
StatusOK
,
response
)
}
}
...
...
route/middleHandle.go
View file @
40ccfdb2
...
@@ -5,6 +5,7 @@ import (
...
@@ -5,6 +5,7 @@ import (
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/resource/config"
"git.hilo.cn/hilo-common/resource/config"
"git.hilo.cn/hilo-common/utils"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"hilo-user/myerr/bizerr"
"hilo-user/myerr/bizerr"
"hilo-user/req"
"hilo-user/req"
...
@@ -133,3 +134,15 @@ func LoggerHandle(c *gin.Context) {
...
@@ -133,3 +134,15 @@ func LoggerHandle(c *gin.Context) {
latency
:=
end
.
Sub
(
start
)
latency
:=
end
.
Sub
(
start
)
mycontext
.
CreateMyContext
(
c
.
Keys
)
.
Log
.
Infof
(
"request end fullPath:%v,url:%v, method: %v, traceId:%v, latency:%v userId:%v"
,
c
.
FullPath
(),
reqUri
,
method
,
traceId
,
latency
,
userId
)
mycontext
.
CreateMyContext
(
c
.
Keys
)
.
Log
.
Infof
(
"request end fullPath:%v,url:%v, method: %v, traceId:%v, latency:%v userId:%v"
,
c
.
FullPath
(),
reqUri
,
method
,
traceId
,
latency
,
userId
)
}
}
// 加密Handle
func
EncryptHandle
(
c
*
gin
.
Context
)
{
header
:=
c
.
Request
.
Header
appVersion
:=
header
.
Get
(
"Appversion"
)
if
len
(
appVersion
)
>
0
{
if
high
,
_
:=
utils
.
CompareVersion
(
appVersion
,
"> 3.9.0"
);
high
{
c
.
Set
(
mycontext
.
InnerEncrypt
,
true
)
}
}
c
.
Next
()
}
route/router.go
View file @
40ccfdb2
...
@@ -28,8 +28,8 @@ func InitRouter() *gin.Engine {
...
@@ -28,8 +28,8 @@ func InitRouter() *gin.Engine {
{
{
user
.
GET
(
"/nameplate"
,
wrapper
(
user_r
.
UserNameplate
))
user
.
GET
(
"/nameplate"
,
wrapper
(
user_r
.
UserNameplate
))
user
.
GET
(
"/bag/:resType"
,
wrapper
(
user_r
.
UserBag
))
user
.
GET
(
"/bag/:resType"
,
wrapper
(
user_r
.
UserBag
))
user
.
GET
(
"/detail"
,
wrapper
(
user_r
.
UserDetail
))
user
.
GET
(
"/detail"
,
EncryptHandle
,
wrapper
(
user_r
.
UserDetail
))
user
.
GET
(
"/detail/:userExternalId"
,
wrapper
(
user_r
.
UserDetailByExternalId
))
user
.
GET
(
"/detail/:userExternalId"
,
EncryptHandle
,
wrapper
(
user_r
.
UserDetailByExternalId
))
}
}
cp
:=
v2
.
Group
(
"/cp"
)
cp
:=
v2
.
Group
(
"/cp"
)
{
{
...
...
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