gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

uuid.go (455B)


      1 package feeds
      2 
      3 // relevant bits from https://github.com/abneptis/GoUUID/blob/master/uuid.go
      4 
      5 import (
      6 	"crypto/rand"
      7 	"fmt"
      8 )
      9 
     10 type UUID [16]byte
     11 
     12 // create a new uuid v4
     13 func NewUUID() *UUID {
     14 	u := &UUID{}
     15 	_, err := rand.Read(u[:16])
     16 	if err != nil {
     17 		panic(err)
     18 	}
     19 
     20 	u[8] = (u[8] | 0x80) & 0xBf
     21 	u[6] = (u[6] | 0x40) & 0x4f
     22 	return u
     23 }
     24 
     25 func (u *UUID) String() string {
     26 	return fmt.Sprintf("%x-%x-%x-%x-%x", u[:4], u[4:6], u[6:8], u[8:10], u[10:])
     27 }