go-tdlib/client/extra.go

21 lines
372 B
Go
Raw Permalink Normal View History

2018-08-30 14:55:42 +00:00
package client
import (
2018-10-23 12:38:10 +00:00
"fmt"
"math/rand"
2018-08-30 14:55:42 +00:00
)
type ExtraGenerator func() string
func UuidV4Generator() ExtraGenerator {
2018-10-23 12:38:10 +00:00
return func() string {
var uuid [16]byte
rand.Read(uuid[:])
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
uuid[6] = (uuid[6] & 0x0f) | 0x40
uuid[8] = (uuid[8] & 0x3f) | 0x80
2018-08-30 14:55:42 +00:00
2018-10-23 12:38:10 +00:00
return fmt.Sprintf("%08x-%04x-%04x-%04x-%012x", uuid[:4], uuid[4:6], uuid[6:8], uuid[8:10], uuid[10:])
}
2018-08-30 14:55:42 +00:00
}