初始化项目 + 数据结构定义
This commit is contained in:
68
trace.go
Normal file
68
trace.go
Normal file
@ -0,0 +1,68 @@
|
||||
// Package trace ...
|
||||
//
|
||||
// Description : trace ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2022-10-14 23:25
|
||||
package trace
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// NewRuntime 获取runtime实例
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 23:26 2022/10/14
|
||||
func NewRuntime(traceID string) *Runtime {
|
||||
return &Runtime{
|
||||
lock: &sync.Mutex{},
|
||||
traceID: traceID,
|
||||
behaviorList: make([]Behavior, 0),
|
||||
}
|
||||
}
|
||||
|
||||
// Runtime ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 23:32 2022/10/14
|
||||
type Runtime struct {
|
||||
lock *sync.Mutex // 锁
|
||||
traceID string // 日志追踪ID
|
||||
behaviorList []*Behavior // 行为列表
|
||||
}
|
||||
|
||||
// StartBehavior 开始一个行为
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 23:41 2022/10/14
|
||||
func (r *Runtime) StartBehavior(action string, data map[string]interface{}) int {
|
||||
if nil == data {
|
||||
data = make(map[string]interface{})
|
||||
}
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
b := &Behavior{
|
||||
ID: len(r.behaviorList),
|
||||
Action: action,
|
||||
Type: BehaviorActionTypeStart,
|
||||
Timestamp: time.Now().UnixNano(),
|
||||
Data: data,
|
||||
}
|
||||
r.behaviorList = append(r.behaviorList, b)
|
||||
return b.ID
|
||||
}
|
||||
|
||||
// FinishBehavior 结束某一个行为
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 23:53 2022/10/14
|
||||
func (r *Runtime) FinishBehavior(behaviorID int) {
|
||||
|
||||
}
|
Reference in New Issue
Block a user