Second Commit

This commit is contained in:
2017-08-06 17:48:01 +02:00
parent 591462e3c1
commit d754bfb686
17 changed files with 1205 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
package generate
import (
"crypto/rand"
"encoding/binary"
"encoding/hex"
"strings"
"time"
)
// ID generates a 24 character hex string from 8 bytes of current time
// in ns and 4 bytes of crypto-random. In practical terms, that makes
// them orderable.
func ID() string {
bytes := make([]byte, 12)
binary.BigEndian.PutUint64(bytes, uint64(time.Now().UnixNano()))
rand.Read(bytes[8:])
return strings.ToLower(hex.EncodeToString(bytes))
}
// SessionID generates a 48 character hex string with crypto/rand
func SessionID() string {
bytes := make([]byte, 24)
rand.Read(bytes)
return strings.ToLower(hex.EncodeToString(bytes))
}