We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent db228fb commit 1d7da97Copy full SHA for 1d7da97
codes/codes.go
@@ -4,6 +4,7 @@ import (
4
"errors"
5
"go.minekube.com/gate/pkg/util/uuid"
6
"math/rand"
7
+ "sync"
8
"time"
9
)
10
@@ -13,6 +14,7 @@ type codeData struct {
13
14
}
15
16
var codes []codeData
17
+var mutex sync.Mutex
18
19
var ErrInvalidCode = errors.New("invalid code")
20
@@ -21,6 +23,9 @@ func init() {
21
23
22
24
25
func New(id uuid.UUID) int {
26
+ mutex.Lock()
27
+ defer mutex.Unlock()
28
+
29
start := rand.Intn(len(codes))
30
i := start
31
@@ -55,6 +60,9 @@ func New(id uuid.UUID) int {
55
60
56
61
57
62
func Retrieve(code int) (uuid.UUID, error) {
63
64
65
58
66
data := codes[code]
59
67
68
if data.time.Add(time.Minute * 5).Before(time.Now()) {
0 commit comments