Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-common
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-common
Commits
7b67793b
You need to sign in or sign up before continuing.
Commit
7b67793b
authored
Jun 21, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
获取traceid
parent
ccf1c3a7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
1 deletion
+15
-1
model.go
domain/model.go
+10
-0
user.go
rpc/user.go
+5
-1
No files found.
domain/model.go
View file @
7b67793b
...
...
@@ -42,6 +42,16 @@ func (m *Model) DB() *gorm.DB {
return
m
.
Db
.
WithContext
(
m
)
}
//获取traceid
func
(
m
*
Model
)
GetTraceId
()
string
{
if
traceIdTemp
,
ok
:=
m
.
Cxt
[
mycontext
.
TRACEID
];
ok
{
if
traceId
,
ok
:=
traceIdTemp
.
(
string
);
ok
{
return
traceId
}
}
return
""
}
// 包装事务
// 注意:需要使用新的model
func
(
m
*
Model
)
Transaction
(
f
func
(
*
Model
)
error
)
error
{
...
...
rpc/user.go
View file @
7b67793b
...
...
@@ -6,6 +6,7 @@ import (
"fmt"
"git.hilo.cn/hilo-common/_const/common"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/resource/consul"
"git.hilo.cn/hilo-common/resource/mysql"
...
...
@@ -435,8 +436,11 @@ func GetUserCp(model *domain.Model, userId mysql.ID) (*CvCp, error) {
Message
string
`json:"message"`
Data
*
CvCp
`json:"data"`
}
header
:=
map
[
string
]
string
{
mycontext
.
TRACEID
:
model
.
GetTraceId
(),
}
_url
:=
fmt
.
Sprintf
(
"%v://%v/inner/user/cp"
,
defaultUserServerScheme
,
getUserHost
())
resp
,
err
:=
HttpGet
(
model
,
_url
,
nil
,
map
[
string
][]
string
{
resp
,
err
:=
HttpGet
(
model
,
_url
,
header
,
map
[
string
][]
string
{
"id"
:
{
fmt
.
Sprintf
(
"%d"
,
userId
)},
})
if
err
!=
nil
{
...
...
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