Skip to content

Commit 4c72001

Browse files
committed
Make changes based on PR comments (#459)
1 parent 3aef60a commit 4c72001

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

idgenerator/aws/xray/aws_xray_idgenerator.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
crand "crypto/rand"
1919
"encoding/binary"
2020
"encoding/hex"
21+
"errors"
2122
"math/rand"
2223
"strconv"
2324
"sync"
@@ -26,16 +27,6 @@ import (
2627
"go.opentelemetry.io/otel/trace"
2728
)
2829

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-
3930
type IDGenerator struct {
4031
sync.Mutex
4132
randSource *rand.Rand
@@ -45,10 +36,7 @@ type IDGenerator struct {
4536
func NewIDGenerator() *IDGenerator {
4637
gen := &IDGenerator{}
4738
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)
5240
gen.randSource = rand.New(rand.NewSource(rngSeed))
5341
return gen
5442
}
@@ -71,8 +59,7 @@ func (gen *IDGenerator) NewTraceID() (trace.TraceID, error) {
7159
tid := trace.TraceID{}
7260
currentTime, err := getCurrentTimeHex()
7361
if err != nil {
74-
var nilTraceID trace.TraceID
75-
return nilTraceID, err
62+
return trace.TraceID{}, err
7663
}
7764
copy(tid[:4], currentTime)
7865
gen.randSource.Read(tid[4:])
@@ -84,7 +71,7 @@ func getCurrentTimeHex() ([]uint8, error) {
8471
currentTime := time.Now().Unix()
8572
currentTimeHex, err := hex.DecodeString(strconv.FormatInt(currentTime, 16))
8673
if err != nil {
87-
return nil, errConvertTimeToHex
74+
return nil, errors.New("cannot convert current timestamp to hex")
8875
}
8976
return currentTimeHex, nil
9077
}

0 commit comments

Comments
 (0)