Core

/app/util/uuid.go (589 B)

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package util

import (
"github.com/google/uuid"
)

var UUIDDefault = uuid.UUID{}

func UUIDFromString(s string) *uuid.UUID {
var retID *uuid.UUID

if len(s) > 0 {
s, err := uuid.Parse(s)
if err == nil {
retID = &s
}
}

return retID
}

func UUIDFromStringOK(s string) uuid.UUID {
if len(s) > 0 {
s, err := uuid.Parse(s)
if err == nil {
return s
}
}
return UUIDDefault
}

func UUIDString(u *uuid.UUID) string {
if u == nil {
return ""
}
return u.String()
}

func UUID() uuid.UUID {
return uuid.New()
}

func UUIDP() *uuid.UUID {
ret := UUID()
return &ret
}