增加读取行为列表方法
This commit is contained in:
38
runtime.go
38
runtime.go
@ -10,6 +10,8 @@ package trace
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/util"
|
||||
)
|
||||
|
||||
// NewRuntime 获取runtime实例
|
||||
@ -18,8 +20,12 @@ import (
|
||||
//
|
||||
// Date : 23:26 2022/10/14
|
||||
func NewRuntime(traceID string) *Runtime {
|
||||
if len(traceID) == 0 {
|
||||
// 若不指定 trace id , 随机生成
|
||||
traceID = util.String.Md5(util.String.GenRandomMd5())
|
||||
}
|
||||
return &Runtime{
|
||||
lock: &sync.Mutex{},
|
||||
lock: &sync.RWMutex{},
|
||||
traceID: traceID,
|
||||
behaviorList: make([]Behavior, 0),
|
||||
}
|
||||
@ -31,9 +37,9 @@ func NewRuntime(traceID string) *Runtime {
|
||||
//
|
||||
// Date : 23:32 2022/10/14
|
||||
type Runtime struct {
|
||||
lock *sync.Mutex // 锁
|
||||
traceID string // 日志追踪ID
|
||||
behaviorList []Behavior // 行为列表
|
||||
lock *sync.RWMutex // 锁
|
||||
traceID string // 日志追踪ID
|
||||
behaviorList []Behavior // 行为列表
|
||||
}
|
||||
|
||||
// StartBehavior 开始一个行为
|
||||
@ -92,3 +98,27 @@ func (r *Runtime) WrapRun(action string, startData map[string]interface{}, logic
|
||||
behaviorID := r.StartBehavior(action, startData)
|
||||
defer r.FinishBehavior(behaviorID, nil)
|
||||
}
|
||||
|
||||
// GetTraceID 获取 trace id
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 00:28 2022/10/15
|
||||
func (r *Runtime) GetTraceID() string {
|
||||
return r.traceID
|
||||
}
|
||||
|
||||
// GetBehaviorList 获取行为列表
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 00:29 2022/10/15
|
||||
func (r *Runtime) GetBehaviorList() []Behavior {
|
||||
r.lock.RLock()
|
||||
defer r.lock.RUnlock()
|
||||
behaviorList := make([]Behavior, 0)
|
||||
for _, item := range r.behaviorList {
|
||||
behaviorList = append(behaviorList, item)
|
||||
}
|
||||
return behaviorList
|
||||
}
|
||||
|
Reference in New Issue
Block a user