-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (37 loc) · 1001 Bytes
/
main.go
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
47
package main
import (
"os"
"fmt"
"path/filepath"
"github.com/dtop/go.uuid5/uuid5"
)
func usage() {
fmt.Fprintf(os.Stderr, "usage: %s [namespace] [name]", filepath.Base(os.Args[0]))
fmt.Println(".")
fmt.Println("Defaults:")
fmt.Println("ns:DNS: 6ba7b810-9dad-11d1-80b4-00c04fd430c8")
fmt.Println("ns:URL: 6ba7b810-9dad-11d1-80b4-00c04fd430c8")
fmt.Println("ns:OID: 6ba7b810-9dad-11d1-80b4-00c04fd430c8")
os.Exit(1)
}
func main() {
if len(os.Args) == 3 {
namespace := os.Args[1]
name := os.Args[2]
uuidgen := &uuid5.UUIDGenerator{Namespace: namespace}
generated, err := uuidgen.GenerateWithName(name)
if err != nil {
println(err.Error())
usage()
os.Exit(1)
}
err = uuidgen.IsValid(generated)
if err != nil {
println(err.Error())
os.Exit(1)
}
println(generated)
os.Exit(0)
}
usage()
}