Commit 7b67793b authored by hujiebin's avatar hujiebin

获取traceid

parent ccf1c3a7
...@@ -42,6 +42,16 @@ func (m *Model) DB() *gorm.DB { ...@@ -42,6 +42,16 @@ func (m *Model) DB() *gorm.DB {
return m.Db.WithContext(m) 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 // 注意:需要使用新的model
func (m *Model) Transaction(f func(*Model) error) error { func (m *Model) Transaction(f func(*Model) error) error {
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"git.hilo.cn/hilo-common/_const/common" "git.hilo.cn/hilo-common/_const/common"
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/mylogrus" "git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/resource/consul" "git.hilo.cn/hilo-common/resource/consul"
"git.hilo.cn/hilo-common/resource/mysql" "git.hilo.cn/hilo-common/resource/mysql"
...@@ -435,8 +436,11 @@ func GetUserCp(model *domain.Model, userId mysql.ID) (*CvCp, error) { ...@@ -435,8 +436,11 @@ func GetUserCp(model *domain.Model, userId mysql.ID) (*CvCp, error) {
Message string `json:"message"` Message string `json:"message"`
Data *CvCp `json:"data"` Data *CvCp `json:"data"`
} }
header := map[string]string{
mycontext.TRACEID: model.GetTraceId(),
}
_url := fmt.Sprintf("%v://%v/inner/user/cp", defaultUserServerScheme, getUserHost()) _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)}, "id": {fmt.Sprintf("%d", userId)},
}) })
if err != nil { if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment