Spaces:
Running
Running
File size: 438 Bytes
bd894b3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | package utils
import (
"time"
"go.uber.org/zap"
)
// TimeFuncWithResult wraps a function call and logs its execution time, returning a result
func TimeFuncWithResult[T any](log *zap.Logger, funcName string, fn func() (T, error)) (T, error) {
start := time.Now()
defer func() {
duration := time.Since(start).Milliseconds()
log.Debug(funcName+" executed", zap.Int64("duration_ms", duration))
}()
return fn()
}
|