From 12d65ebe1de6fcbe26e3aeee0b73767a70deb74f Mon Sep 17 00:00:00 2001 From: Pedro Albanese <68971450+pedroalbanese@users.noreply.github.com> Date: Wed, 16 Jun 2021 07:41:54 -0300 Subject: [PATCH 01/12] Add files via upload --- cmd/uuid/main.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 cmd/uuid/main.go diff --git a/cmd/uuid/main.go b/cmd/uuid/main.go new file mode 100644 index 0000000..c8ad079 --- /dev/null +++ b/cmd/uuid/main.go @@ -0,0 +1,52 @@ +package main + +import ( + "bytes" + "flag" + "fmt" + "time" + "io" + "os" + "strings" + + "github.com/google/uuid" +) + +var ( + parse = flag.String("d", "", "Parse given UUID.") + person = flag.Bool("p", false, "Generate DCE Person UUID.") + random = flag.Bool("r", false, "Generate Random UUID.") +) + +func main() { + flag.Parse() + var lreader io.Reader + + if *parse == "" && *person == false { + u := uuid.New() + fmt.Printf("%s", u) + } else if *parse == "" && *person == true { + u, _ := uuid.NewDCEPerson() + fmt.Printf("%s", u) + } else if *parse == "" && *random == true { + u, _ := uuid.NewRandom() + fmt.Printf("%s", u) + } else if *parse == "-" { + lreader = os.Stdin + } else if *parse != "" && *parse != "-" { + lreader = strings.NewReader(*parse) + + buf := new(bytes.Buffer) + buf.ReadFrom(lreader) + s := buf.String() + + uuid, _ := uuid.Parse(s) + fmt.Printf("Successfully parsed UID : %s\n", uuid) + + id := uuid + t := id.Time() + sec, nsec := t.UnixTime() + timeStamp := time.Unix(sec, nsec) + fmt.Printf("The id was generated at : %v \n", timeStamp.Format("2006-01-02 Mon 15:04:05.000Z -0700")) + } +} \ No newline at end of file From 2e41463c02bf5e7c50f62dc0d5cc0f11fefb4096 Mon Sep 17 00:00:00 2001 From: Pedro Albanese <68971450+pedroalbanese@users.noreply.github.com> Date: Wed, 16 Jun 2021 07:43:25 -0300 Subject: [PATCH 02/12] Update main.go --- cmd/uuid/main.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/uuid/main.go b/cmd/uuid/main.go index c8ad079..51c58c3 100644 --- a/cmd/uuid/main.go +++ b/cmd/uuid/main.go @@ -4,22 +4,22 @@ import ( "bytes" "flag" "fmt" + "io" + "os" + "strings" "time" - "io" - "os" - "strings" "github.com/google/uuid" ) var ( - parse = flag.String("d", "", "Parse given UUID.") + parse = flag.String("d", "", "Parse given UUID.") person = flag.Bool("p", false, "Generate DCE Person UUID.") random = flag.Bool("r", false, "Generate Random UUID.") ) func main() { - flag.Parse() + flag.Parse() var lreader io.Reader if *parse == "" && *person == false { @@ -38,7 +38,7 @@ func main() { buf := new(bytes.Buffer) buf.ReadFrom(lreader) - s := buf.String() + s := buf.String() uuid, _ := uuid.Parse(s) fmt.Printf("Successfully parsed UID : %s\n", uuid) @@ -49,4 +49,4 @@ func main() { timeStamp := time.Unix(sec, nsec) fmt.Printf("The id was generated at : %v \n", timeStamp.Format("2006-01-02 Mon 15:04:05.000Z -0700")) } -} \ No newline at end of file +} From 8f347dab34c652843abe94a234cab0757144837c Mon Sep 17 00:00:00 2001 From: Pedro Albanese <68971450+pedroalbanese@users.noreply.github.com> Date: Wed, 16 Jun 2021 08:05:08 -0300 Subject: [PATCH 03/12] Update main.go --- cmd/uuid/main.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/cmd/uuid/main.go b/cmd/uuid/main.go index 51c58c3..add7e4e 100644 --- a/cmd/uuid/main.go +++ b/cmd/uuid/main.go @@ -31,22 +31,23 @@ func main() { } else if *parse == "" && *random == true { u, _ := uuid.NewRandom() fmt.Printf("%s", u) - } else if *parse == "-" { - lreader = os.Stdin - } else if *parse != "" && *parse != "-" { - lreader = strings.NewReader(*parse) - + } else if *parse != "" { + if *parse == "-" { + lreader = os.Stdin + } else if *parse != "-" { + lreader = strings.NewReader(*parse) + } buf := new(bytes.Buffer) buf.ReadFrom(lreader) s := buf.String() uuid, _ := uuid.Parse(s) - fmt.Printf("Successfully parsed UID : %s\n", uuid) + fmt.Printf("uuid : %s\n", uuid) id := uuid t := id.Time() sec, nsec := t.UnixTime() timeStamp := time.Unix(sec, nsec) - fmt.Printf("The id was generated at : %v \n", timeStamp.Format("2006-01-02 Mon 15:04:05.000Z -0700")) + fmt.Printf("time : %v \n", timeStamp.Format("2006-01-02 Mon 15:04:05.000Z -0700")) } } From a901b6cc1825e0a563e23f63cb06418408f8ed45 Mon Sep 17 00:00:00 2001 From: Pedro Albanese <68971450+pedroalbanese@users.noreply.github.com> Date: Wed, 16 Jun 2021 08:21:53 -0300 Subject: [PATCH 04/12] Update main.go --- cmd/uuid/main.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/cmd/uuid/main.go b/cmd/uuid/main.go index add7e4e..88b8f4e 100644 --- a/cmd/uuid/main.go +++ b/cmd/uuid/main.go @@ -14,7 +14,6 @@ import ( var ( parse = flag.String("d", "", "Parse given UUID.") - person = flag.Bool("p", false, "Generate DCE Person UUID.") random = flag.Bool("r", false, "Generate Random UUID.") ) @@ -22,12 +21,9 @@ func main() { flag.Parse() var lreader io.Reader - if *parse == "" && *person == false { + if *parse == "" { u := uuid.New() fmt.Printf("%s", u) - } else if *parse == "" && *person == true { - u, _ := uuid.NewDCEPerson() - fmt.Printf("%s", u) } else if *parse == "" && *random == true { u, _ := uuid.NewRandom() fmt.Printf("%s", u) From 237cad2a9332ed9ed962252b5eec56f4360e54fe Mon Sep 17 00:00:00 2001 From: Pedro Albanese <68971450+pedroalbanese@users.noreply.github.com> Date: Wed, 16 Jun 2021 08:27:58 -0300 Subject: [PATCH 05/12] Update main.go --- cmd/uuid/main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/uuid/main.go b/cmd/uuid/main.go index 88b8f4e..cc27c77 100644 --- a/cmd/uuid/main.go +++ b/cmd/uuid/main.go @@ -21,11 +21,11 @@ func main() { flag.Parse() var lreader io.Reader - if *parse == "" { - u := uuid.New() + if *parse == "" && *random == false { + u, _ := uuid.NewUUID() fmt.Printf("%s", u) } else if *parse == "" && *random == true { - u, _ := uuid.NewRandom() + u := uuid.New() fmt.Printf("%s", u) } else if *parse != "" { if *parse == "-" { @@ -44,6 +44,6 @@ func main() { t := id.Time() sec, nsec := t.UnixTime() timeStamp := time.Unix(sec, nsec) - fmt.Printf("time : %v \n", timeStamp.Format("2006-01-02 Mon 15:04:05.000Z -0700")) + fmt.Printf("date : %v \n", timeStamp.Format("2006-01-02 Mon 15:04:05.000Z -0700")) } } From 7169adbd565990a8c4207710b6a7a974fbef3c29 Mon Sep 17 00:00:00 2001 From: Pedro Albanese <68971450+pedroalbanese@users.noreply.github.com> Date: Tue, 22 Jun 2021 17:13:56 -0300 Subject: [PATCH 06/12] Update main.go --- cmd/uuid/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/uuid/main.go b/cmd/uuid/main.go index cc27c77..2f3d539 100644 --- a/cmd/uuid/main.go +++ b/cmd/uuid/main.go @@ -23,10 +23,10 @@ func main() { if *parse == "" && *random == false { u, _ := uuid.NewUUID() - fmt.Printf("%s", u) + fmt.Printf("%s\n", u) } else if *parse == "" && *random == true { u := uuid.New() - fmt.Printf("%s", u) + fmt.Printf("%s\n", u) } else if *parse != "" { if *parse == "-" { lreader = os.Stdin From 47821a15214a0b7093b03d0a0dbb094456c8ab02 Mon Sep 17 00:00:00 2001 From: Pedro Albanese <68971450+pedroalbanese@users.noreply.github.com> Date: Thu, 25 Nov 2021 13:02:31 -0300 Subject: [PATCH 07/12] Parse STDIN --- cmd/uuid/main.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/uuid/main.go b/cmd/uuid/main.go index 2f3d539..088608b 100644 --- a/cmd/uuid/main.go +++ b/cmd/uuid/main.go @@ -36,14 +36,15 @@ func main() { buf := new(bytes.Buffer) buf.ReadFrom(lreader) s := buf.String() + s = strings.TrimSuffix(s, "\n") uuid, _ := uuid.Parse(s) - fmt.Printf("uuid : %s\n", uuid) + fmt.Printf("UUID= %s\n", uuid) id := uuid t := id.Time() sec, nsec := t.UnixTime() timeStamp := time.Unix(sec, nsec) - fmt.Printf("date : %v \n", timeStamp.Format("2006-01-02 Mon 15:04:05.000Z -0700")) + fmt.Printf("DATE= %v \n", timeStamp.Format("2006-01-02 Mon 15:04:05.00000Z -0700")) } } From cc72d8c3ab3fbb520e14448bbca4581f83d08ccc Mon Sep 17 00:00:00 2001 From: "Pedro F. Albanese" <68971450+pedroalbanese@users.noreply.github.com> Date: Fri, 3 Dec 2021 18:46:45 -0300 Subject: [PATCH 08/12] Version 1 --- cmd/uuid/main.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/cmd/uuid/main.go b/cmd/uuid/main.go index 088608b..a26e3f9 100644 --- a/cmd/uuid/main.go +++ b/cmd/uuid/main.go @@ -13,20 +13,16 @@ import ( ) var ( - parse = flag.String("d", "", "Parse given UUID.") - random = flag.Bool("r", false, "Generate Random UUID.") + parse = flag.String("d", "", "Parse given UUID. ('-' for STDIN)") ) func main() { flag.Parse() var lreader io.Reader - if *parse == "" && *random == false { + if *parse == "" { u, _ := uuid.NewUUID() fmt.Printf("%s\n", u) - } else if *parse == "" && *random == true { - u := uuid.New() - fmt.Printf("%s\n", u) } else if *parse != "" { if *parse == "-" { lreader = os.Stdin From e7b775b995d32b75855b6500b06e6d3ebc371f6c Mon Sep 17 00:00:00 2001 From: "Pedro F. Albanese" <68971450+pedroalbanese@users.noreply.github.com> Date: Fri, 3 Dec 2021 18:52:37 -0300 Subject: [PATCH 09/12] Copyright --- LICENSE | 1 + 1 file changed, 1 insertion(+) diff --git a/LICENSE b/LICENSE index 5dc6826..a83e266 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,5 @@ Copyright (c) 2009,2014 Google Inc. All rights reserved. +Copyright (c) 2021 Pedro Albanese. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are From 7b6ad076f8ada9811e0fc6c28f8114943909e578 Mon Sep 17 00:00:00 2001 From: "Pedro F. Albanese" <68971450+pedroalbanese@users.noreply.github.com> Date: Wed, 12 Oct 2022 18:27:24 -0300 Subject: [PATCH 10/12] Update go.mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index fc84cd7..ba697e0 100644 --- a/go.mod +++ b/go.mod @@ -1 +1 @@ -module github.com/google/uuid +module github.com/pedroalbanese/uuid From 8fe566f99118910b966194154177db84efa186d7 Mon Sep 17 00:00:00 2001 From: "Pedro F. Albanese" <68971450+pedroalbanese@users.noreply.github.com> Date: Tue, 25 Jul 2023 19:27:16 -0300 Subject: [PATCH 11/12] Update main.go --- cmd/uuid/main.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cmd/uuid/main.go b/cmd/uuid/main.go index a26e3f9..b07b6d5 100644 --- a/cmd/uuid/main.go +++ b/cmd/uuid/main.go @@ -1,3 +1,4 @@ +// Package main is the main package for the UUID generator application. package main import ( @@ -12,35 +13,42 @@ import ( "github.com/google/uuid" ) +// parse is a command-line flag to parse the given UUID. ('-' for STDIN) var ( - parse = flag.String("d", "", "Parse given UUID. ('-' for STDIN)") + parse = flag.String("d", "", "Parse given UUID. ('-' for STDIN)") ) func main() { flag.Parse() var lreader io.Reader + // If no UUID is given as input, generate a new UUID and print it. if *parse == "" { u, _ := uuid.NewUUID() fmt.Printf("%s\n", u) - } else if *parse != "" { - if *parse == "-" { + } else if *parse != "" { // If a UUID is provided as input, parse and process it. + if *parse == "-" { // If input is "-", read from STDIN. lreader = os.Stdin - } else if *parse != "-" { + } else if *parse != "-" { // Otherwise, read from the provided input string. lreader = strings.NewReader(*parse) } + buf := new(bytes.Buffer) buf.ReadFrom(lreader) s := buf.String() s = strings.TrimSuffix(s, "\n") + // Parse the UUID string to a UUID object. uuid, _ := uuid.Parse(s) fmt.Printf("UUID= %s\n", uuid) + // Get the timestamp information from the parsed UUID. id := uuid t := id.Time() sec, nsec := t.UnixTime() timeStamp := time.Unix(sec, nsec) + + // Print the timestamp in a formatted date string. fmt.Printf("DATE= %v \n", timeStamp.Format("2006-01-02 Mon 15:04:05.00000Z -0700")) } } From 3dbc77e44282a73315e89b19b4f1f9cefc4df57e Mon Sep 17 00:00:00 2001 From: "Pedro F. Albanese" <68971450+pedroalbanese@users.noreply.github.com> Date: Tue, 25 Jul 2023 19:32:25 -0300 Subject: [PATCH 12/12] Update main.go --- cmd/uuid/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/uuid/main.go b/cmd/uuid/main.go index b07b6d5..6b65834 100644 --- a/cmd/uuid/main.go +++ b/cmd/uuid/main.go @@ -29,7 +29,7 @@ func main() { } else if *parse != "" { // If a UUID is provided as input, parse and process it. if *parse == "-" { // If input is "-", read from STDIN. lreader = os.Stdin - } else if *parse != "-" { // Otherwise, read from the provided input string. + } else { // Otherwise, read from the provided input string. lreader = strings.NewReader(*parse) }