Commit 7b67793b authored by hujiebin's avatar hujiebin

获取traceid

parent ccf1c3a7
......@@ -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 {
......
......@@ -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 {
......
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