suwako / uuid-go アーカイブ

このリポジトリはアーカイブされています。読むだけで、プッシュやイシューの変更は出来ません。

最初コミット

諏訪子 <suwako@076.moe>、2026-06-14 16:01
コミット aa6167dce9b1f13be170fedd38ad7d5e9ec24ebb ・ファイルを見る

3個のファイル、+52 -0

追加 LICENSE.md
@@ -0,0 +1,21 @@
1+# 076 Free License
2+
3+Copyright (c) テクニカル諏訪子
4+
5+Permission is hereby granted to any person obtaining a copy of the software
6+uuid-go (the "Software") to use, modify, merge, copy, publish, distribute,
7+sublicense, and/or sell copies of the Software, subject to the following conditions:
8+
9+ 1. **Origin Attribution**:
10+ - You must not misrepresent the origin of the Software; you must not claim
11+ you created the original Software.
12+ 2. **Notice Preservation**:
13+ - This license and the above copyright notice must remain intact in all copies
14+ of the source code.
15+
16+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
17+INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
18+PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20+CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
21+OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
追加 README.md
@@ -0,0 +1,5 @@
1+# UUID (Go言語版)
2+
3+```sh
4+$ go build -ldflags "-w -s" uuid.go
5+```
追加 uuid.go
@@ -0,0 +1,26 @@
1+package main
2+
3+import (
4+ "crypto/rand"
5+ "fmt"
6+)
7+
8+func main() {
9+ data := make([]byte, 16)
10+ _, err := rand.Read(data)
11+ if err != nil {
12+ fmt.Println(err)
13+ return
14+ }
15+
16+ data[6] = (data[6] & 0x0F) | 0x40
17+ data[8] = (data[8] & 0x3F) | 0x80
18+ fmt.Printf(
19+ "%x-%x-%x-%x-%x\n",
20+ data[0:4],
21+ data[4:6],
22+ data[6:8],
23+ data[8:10],
24+ data[10:16],
25+ )
26+}