Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-group
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
hujiebin
hilo-group
Compare Revisions
master...feature/encrypt
Source
feature/encrypt
Select Git revision
...
Target
master
Select Git revision
Compare
Commits (4)
feature/encrypt
· 469ec7ae
hujiebin
authored
Jun 25, 2023
469ec7ae
feat:分页兼容
· 7f1d1d32
hujiebin
authored
Jun 25, 2023
7f1d1d32
feat:部分接口加密
· 8145bea5
hujiebin
authored
Jun 25, 2023
8145bea5
Merge branch 'master' into feature/encrypt
· df074b78
hujiebin
authored
Jul 07, 2023
df074b78
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
14 deletions
+46
-14
response.go
resp/response.go
+30
-11
middleHandle.go
route/middleHandle.go
+13
-0
router.go
route/router.go
+3
-3
No files found.
resp/response.go
View file @
df074b78
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"encoding/json"
"encoding/json"
"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/utils"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"hilo-group/myerr"
"hilo-group/myerr"
"net/http"
"net/http"
...
@@ -16,6 +17,7 @@ type Response struct {
...
@@ -16,6 +17,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"`
// 数据
}
}
/**
/**
...
@@ -30,7 +32,12 @@ func ResponseOk(c *gin.Context, data interface{}) {
...
@@ -30,7 +32,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
)
...
@@ -116,15 +123,21 @@ type Page struct {
...
@@ -116,15 +123,21 @@ type Page struct {
func
ResponsePageOk
(
c
*
gin
.
Context
,
data
interface
{},
total
uint
,
index
int
)
{
func
ResponsePageOk
(
c
*
gin
.
Context
,
data
interface
{},
total
uint
,
index
int
)
{
// always return http.StatusOK
// always return http.StatusOK
pageData
:=
Page
{
Total
:
total
,
Index
:
index
,
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
:
Page
{
}
Total
:
total
,
if
_
,
ok
:=
c
.
Get
(
mycontext
.
InnerEncrypt
);
ok
{
Index
:
index
,
//response.Edata = utils.EncryptionData(data, []byte("484194d4d0f968a7"))
Data
:
data
,
response
.
Edata
=
utils
.
EncryptionData
(
pageData
,
[]
byte
(
"hilo!@#$%^&*()_+"
))
},
}
else
{
response
.
Data
=
pageData
}
}
printResponseBody
(
c
,
&
response
)
printResponseBody
(
c
,
&
response
)
...
@@ -149,15 +162,21 @@ func ResponsePageBaseOk(c *gin.Context, data interface{}, nextPageIndex int, has
...
@@ -149,15 +162,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
:=
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
:
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 @
df074b78
...
@@ -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-group/myerr/bizerr"
"hilo-group/myerr/bizerr"
"hilo-group/req"
"hilo-group/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 @
df074b78
...
@@ -31,8 +31,8 @@ func InitRouter() *gin.Engine {
...
@@ -31,8 +31,8 @@ func InitRouter() *gin.Engine {
//
//
imGroup
.
POST
(
"/group"
,
wrapper
(
group_r
.
CreateGroup
))
imGroup
.
POST
(
"/group"
,
wrapper
(
group_r
.
CreateGroup
))
imGroup
.
DELETE
(
"/group/:groupId"
,
wrapper
(
group_r
.
DestroyGroup
))
imGroup
.
DELETE
(
"/group/:groupId"
,
wrapper
(
group_r
.
DestroyGroup
))
imGroup
.
GET
(
"/group/:code"
,
wrapper
(
group_r
.
GetGroupInfo
))
imGroup
.
GET
(
"/group/:code"
,
EncryptHandle
,
wrapper
(
group_r
.
GetGroupInfo
))
imGroup
.
GET
(
"/detail/:groupId"
,
wrapper
(
group_r
.
GetGroupDetail
))
imGroup
.
GET
(
"/detail/:groupId"
,
EncryptHandle
,
wrapper
(
group_r
.
GetGroupDetail
))
imGroup
.
PUT
(
"/group/:groupId"
,
wrapper
(
group_r
.
ModifyGroupInfo
))
imGroup
.
PUT
(
"/group/:groupId"
,
wrapper
(
group_r
.
ModifyGroupInfo
))
imGroup
.
GET
(
"/search/:code"
,
wrapper
(
group_r
.
SearchGroup
))
imGroup
.
GET
(
"/search/:code"
,
wrapper
(
group_r
.
SearchGroup
))
imGroup
.
DELETE
(
"/member/:groupId"
,
wrapper
(
group_r
.
LeaveGroup
))
imGroup
.
DELETE
(
"/member/:groupId"
,
wrapper
(
group_r
.
LeaveGroup
))
...
@@ -48,7 +48,7 @@ func InitRouter() *gin.Engine {
...
@@ -48,7 +48,7 @@ func InitRouter() *gin.Engine {
imGroup
.
GET
(
"/ownGroup"
,
wrapper
(
group_r
.
GetOwnGroup
))
imGroup
.
GET
(
"/ownGroup"
,
wrapper
(
group_r
.
GetOwnGroup
))
imGroup
.
GET
(
"/theirGroup/:userExternalId"
,
wrapper
(
group_r
.
GetTheirGroups
))
imGroup
.
GET
(
"/theirGroup/:userExternalId"
,
wrapper
(
group_r
.
GetTheirGroups
))
imGroup
.
PUT
(
"/pluginReady/:groupId"
,
wrapper
(
group_r
.
PluginReady
))
imGroup
.
PUT
(
"/pluginReady/:groupId"
,
wrapper
(
group_r
.
PluginReady
))
imGroup
.
GET
(
"/roomInfo/:groupId"
,
wrapper
(
group_r
.
GetRoomInfo
))
imGroup
.
GET
(
"/roomInfo/:groupId"
,
EncryptHandle
,
wrapper
(
group_r
.
GetRoomInfo
))
//
//
imGroup
.
GET
(
"/password/:groupId"
,
wrapper
(
group_r
.
GetGroupPassword
))
imGroup
.
GET
(
"/password/:groupId"
,
wrapper
(
group_r
.
GetGroupPassword
))
imGroup
.
GET
(
"/role/:groupId"
,
wrapper
(
group_r
.
GetGroupRole
))
imGroup
.
GET
(
"/role/:groupId"
,
wrapper
(
group_r
.
GetGroupRole
))
...
...