Core functionality for new aiterp.net servers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
639 B

7 years ago
  1. package generate
  2. import (
  3. "crypto/rand"
  4. "encoding/binary"
  5. "encoding/hex"
  6. "strings"
  7. "time"
  8. )
  9. // ID generates a 24 character hex string from 8 bytes of current time
  10. // in ns and 4 bytes of crypto-random. In practical terms, that makes
  11. // them orderable.
  12. func ID() string {
  13. bytes := make([]byte, 12)
  14. binary.BigEndian.PutUint64(bytes, uint64(time.Now().UnixNano()))
  15. rand.Read(bytes[8:])
  16. return strings.ToLower(hex.EncodeToString(bytes))
  17. }
  18. // SessionID generates a 48 character hex string with crypto/rand
  19. func SessionID() string {
  20. bytes := make([]byte, 24)
  21. rand.Read(bytes)
  22. return strings.ToLower(hex.EncodeToString(bytes))
  23. }