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
a8d0809d
Commit
a8d0809d
authored
Mar 01, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:补上traceId
parent
b4d52c16
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
2 deletions
+7
-2
middleHandle.go
route/middleHandle.go
+1
-1
utils.go
route/utils.go
+6
-1
No files found.
route/middleHandle.go
View file @
a8d0809d
...
...
@@ -90,7 +90,7 @@ func LoggerHandle(c *gin.Context) {
start
:=
time
.
Now
()
clientIp
:=
c
.
ClientIP
()
method
:=
c
.
Request
.
Method
traceId
:=
genTraceId
()
traceId
:=
genTraceId
(
c
)
reqUri
:=
c
.
Request
.
RequestURI
c
.
Set
(
mycontext
.
TRACEID
,
traceId
)
//
...
...
route/utils.go
View file @
a8d0809d
package
route
import
(
"git.hilo.cn/hilo-common/mycontext"
"github.com/gin-gonic/gin"
uuid
"github.com/satori/go.uuid"
"strings"
)
func
genTraceId
()
string
{
func
genTraceId
(
c
*
gin
.
Context
)
string
{
if
trace
:=
c
.
GetHeader
(
mycontext
.
TRACEID
);
len
(
trace
)
>
0
{
return
trace
}
traceId
:=
strings
.
Replace
(
uuid
.
NewV4
()
.
String
(),
"-"
,
""
,
-
1
)
traceId
=
traceId
[
:
len
(
traceId
)
/
2
]
return
traceId
...
...
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