@@ -18,6 +18,7 @@ import (
18
18
crand "crypto/rand"
19
19
"encoding/binary"
20
20
"encoding/hex"
21
+ "errors"
21
22
"math/rand"
22
23
"strconv"
23
24
"sync"
@@ -26,16 +27,6 @@ import (
26
27
"go.opentelemetry.io/otel/trace"
27
28
)
28
29
29
- const (
30
- errConvertTimeToHex errorConst = "cannot convert current timestamp to hex"
31
- )
32
-
33
- type errorConst string
34
-
35
- func (e errorConst ) Error () string {
36
- return string (e )
37
- }
38
-
39
30
type IDGenerator struct {
40
31
sync.Mutex
41
32
randSource * rand.Rand
@@ -45,10 +36,7 @@ type IDGenerator struct {
45
36
func NewIDGenerator () * IDGenerator {
46
37
gen := & IDGenerator {}
47
38
var rngSeed int64
48
- err := binary .Read (crand .Reader , binary .LittleEndian , & rngSeed )
49
- if err != nil {
50
- panic (err )
51
- }
39
+ _ = binary .Read (crand .Reader , binary .LittleEndian , & rngSeed )
52
40
gen .randSource = rand .New (rand .NewSource (rngSeed ))
53
41
return gen
54
42
}
@@ -71,8 +59,7 @@ func (gen *IDGenerator) NewTraceID() (trace.TraceID, error) {
71
59
tid := trace.TraceID {}
72
60
currentTime , err := getCurrentTimeHex ()
73
61
if err != nil {
74
- var nilTraceID trace.TraceID
75
- return nilTraceID , err
62
+ return trace.TraceID {}, err
76
63
}
77
64
copy (tid [:4 ], currentTime )
78
65
gen .randSource .Read (tid [4 :])
@@ -84,7 +71,7 @@ func getCurrentTimeHex() ([]uint8, error) {
84
71
currentTime := time .Now ().Unix ()
85
72
currentTimeHex , err := hex .DecodeString (strconv .FormatInt (currentTime , 16 ))
86
73
if err != nil {
87
- return nil , errConvertTimeToHex
74
+ return nil , errors . New ( "cannot convert current timestamp to hex" )
88
75
}
89
76
return currentTimeHex , nil
90
77
}
0 commit comments