package traces import ( "context" "joybuywork/internal/app" "fmt" "time" ) type FnTimer struct { *FnTimers name string start time.Time } func (ft FnTimer) Stop() { if ft.FnTimers == nil { return } elapsed := time.Since(ft.start) ft.content = append(ft.content, fmt.Sprintf("[函数耗时] %s: %s\n", ft.name, elapsed)) } type FnTimers struct { ctx context.Context content []string } func NewFnTimers(ctx context.Context) *FnTimers { return &FnTimers{ ctx: ctx, } } func (s *FnTimers) Trace(name string) (ft FnTimer) { if s == nil { return } return FnTimer{ FnTimers: s, name: name, start: time.Now(), } } func (s *FnTimers) Push() { if s == nil { return } var str string for _, t := range s.content { str += t + "\n" } app.FeishuNormalSend(str) }