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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
---
title: uuid functions
menu:
main:
parent: functions
---
Functions for generating, parsing, and manipulating UUIDs.
A UUID is a 128 bit (16 byte) _Universal Unique IDentifier_ as defined
in [RFC 4122][]. Only RFC 4112-variant UUIDs can be generated, but all variants
(even invalid ones) can be parsed and manipulated. Also, gomplate only supports
generating version 1 and 4 UUIDs (with 4 being the most commonly-used variety
these days). Versions 2, 3, and 5 are able to be supported: [log an issue][] if
this is required for your use-case.
[RFC 4122]: https://en.wikipedia.org/wiki/Universally_unique_identifier
[log an issue]: https://github.com/hairyhenderson/gomplate/issues/new
## `uuid.V1`
Create a version 1 UUID (based on the current MAC address and the current date/time).
Use [`uuid.V4`](#uuidv4) instead in most cases.
_Added in gomplate [v3.4.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.4.0)_
### Usage
```
uuid.V1
```
### Examples
```console
$ gomplate -i '{{ uuid.V1 }}'
4d757e54-446d-11e9-a8fa-72000877c7b0
```
## `uuid.V4`
Create a version 4 UUID (randomly generated).
This function consumes entropy.
_Added in gomplate [v3.4.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.4.0)_
### Usage
```
uuid.V4
```
### Examples
```console
$ gomplate -i '{{ uuid.V4 }}'
40b3c2d2-e491-4b19-94cd-461e6fa35a60
```
## `uuid.Nil`
Returns the _nil_ UUID, that is, `00000000-0000-0000-0000-000000000000`,
mostly for testing scenarios.
_Added in gomplate [v3.4.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.4.0)_
### Usage
```
uuid.Nil
```
### Examples
```console
$ gomplate -i '{{ uuid.Nil }}'
00000000-0000-0000-0000-000000000000
```
## `uuid.IsValid`
Checks that the given UUID is in the correct format. It does not validate
whether the version or variant are correct.
_Added in gomplate [v3.4.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.4.0)_
### Usage
```
uuid.IsValid uuid
```
```
uuid | uuid.IsValid
```
### Arguments
| name | description |
|------|-------------|
| `uuid` | _(required)_ The uuid to check |
### Examples
```console
$ gomplate -i '{{ if uuid.IsValid "totally invalid" }}valid{{ else }}invalid{{ end }}'
invalid
```
```console
$ gomplate -i '{{ uuid.IsValid "urn:uuid:12345678-90ab-cdef-fedc-ba9876543210" }}'
true
```
## `uuid.Parse`
Parse a UUID for further manipulation or inspection.
This function returns a `UUID` struct, as defined in the [github.com/google/uuid](https://godoc.org/github.com/google/uuid#UUID) package. See the docs for examples of functions or fields you can call.
Both the standard UUID forms of `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` and
`urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` are decoded as well as the
Microsoft encoding `{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}` and the raw hex
encoding (`xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`).
_Added in gomplate [v3.4.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.4.0)_
### Usage
```
uuid.Parse uuid
```
```
uuid | uuid.Parse
```
### Arguments
| name | description |
|------|-------------|
| `uuid` | _(required)_ The uuid to parse |
### Examples
```console
$ gomplate -i '{{ $u := uuid.Parse uuid.V4 }}{{ $u.Version }}, {{ $u.Variant}}'
VERSION_4, RFC4122
```
```console
$ gomplate -i '{{ (uuid.Parse "000001f5-4470-21e9-9b00-72000877c7b0").Domain }}'
Person
```
|