-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add README & CLI tool to inspect TraceId timestamp
- Loading branch information
1 parent
09fb6aa
commit 86d3c9a
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# TraceId | ||
|
||
Go package that helps create and pass `TraceId` header among microservices for simple tracing capabilities and log grouping. | ||
|
||
The generated `TraceId` value is [UUIDv7](https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format-03#name-uuid-version-7), which lets you infer the time of the trace creation from its value. | ||
|
||
## Example | ||
|
||
TODO | ||
|
||
## Get time from UUIDv7 value | ||
|
||
``` | ||
$ go run github.com/go-chi/traceid/cmd/traceid 018e0ee7-3605-7d75-b344-01062c6fd8bc | ||
2024-03-05 14:56:57.477 +0100 CET | ||
``` | ||
|
||
### Create new UUIDv7: | ||
``` | ||
$ go run github.com/go-chi/traceid/cmd/traceid | ||
018e0ee7-3605-7d75-b344-01062c6fd8bc | ||
``` | ||
|
||
## License | ||
[MIT](./LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"time" | ||
|
||
"github.com/google/uuid" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) <= 1 { | ||
fmt.Println(uuid.Must(uuid.NewV7())) | ||
os.Exit(0) | ||
} | ||
|
||
uuid, err := uuid.Parse(os.Args[1]) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
t := time.Unix(uuid.Time().UnixTime()) | ||
fmt.Println(t) | ||
} |