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