-
Notifications
You must be signed in to change notification settings - Fork 0
/
base64Use.go
64 lines (54 loc) · 984 Bytes
/
base64Use.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"crypto/rand"
"encoding/base64"
"fmt"
"io"
"os"
"sync"
)
func main() {
//fmt.Println(MakeKey())
testGenReqId()
}
func testGenReqId() {
mymap := map[string]int{}
keys := make(chan string)
var wg sync.WaitGroup
wg.Add(2)
go func() {
for i := 0; i < 1000000; i++ {
keys <- genReqId()
}
wg.Done()
}()
go func() {
for i := 0; i < 1000000; i++ {
keys <- genReqId()
}
wg.Done()
}()
go func() {
for key := range keys {
if _, ok := mymap[key]; ok {
fmt.Printf("key = %+v dup\n", key)
os.Exit(3)
}
fmt.Printf("key = %+v\n", key)
mymap[key] = 1
}
}()
wg.Wait()
close(keys)
}
func MakeKey() string {
var b [30]byte
io.ReadFull(rand.Reader, b[:])
return base64.URLEncoding.EncodeToString(b[:])
}
func genReqId() string {
var b [12]byte
//binary.LittleEndian.PutUint32(b[:], uint32(time.Now().UnixNano()%4294967291))
io.ReadFull(rand.Reader, b[:])
return base64.URLEncoding.EncodeToString(b[:])
}