Blame view

guid.go 377 Bytes
1c83dc241   Marko Tikvić   GUID and timer
1
2
3
  package webutility
  
  import (
1c83dc241   Marko Tikvić   GUID and timer
4
  	"fmt"
1b51eed04   Marko Tikvić   pdf helper
5
  	"math/rand"
1c83dc241   Marko Tikvić   GUID and timer
6
  )
1b51eed04   Marko Tikvić   pdf helper
7
8
9
  func SeedGUID(seed int64) {
  	rand.Seed(seed)
  }
1c83dc241   Marko Tikvić   GUID and timer
10
11
12
13
14
15
16
17
18
19
  // GUID ...
  func GUID() (string, error) {
  	b := make([]byte, 16)
  	_, err := rand.Read(b)
  	if err != nil {
  		return "", err
  	}
  	id := fmt.Sprintf("%x-%x-%x-%x-%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:])
  	return id, nil
  }
1b51eed04   Marko Tikvić   pdf helper
20
21
22
23
24
  
  func NewGUID() string {
  	id, _ := GUID()
  	return id
  }