← Runnable Projects

阅读中文版本

Go UUIDv7 Generator CLI

Go UUIDv7 Generator — a runnable go project with source, install and run commands, and expected output.

intermediategounverified

Project

go-uuid-v7-cli

Entry point: main.go

Install

go run main.go 5

Run

go run main.go 5

Test

go test

Expected output

Generates 5 UUIDv7 strings (timestamp + random) and prints them.

Dependencies

  • go >=1.22

Verification evidence

Source reviewed against go standard library APIs. Commands verified for syntax; execution not yet exercised in CI.

Security note

Reads only the file or arguments passed on the command line; makes no network requests and writes nothing outside stdout.

What it does

Go UUIDv7 Generator CLI is a self-contained go command-line program. Generates 5 UUIDv7 strings (timestamp + random) and prints them.

Install and run

go run main.go 5
go run main.go 5

Project structure

go-uuid-v7-cli/
├── main.go
└── README snippet above

Key source

// main.go
package main
import ("crypto/rand"; "fmt"; "os"; "strconv"; "time")
func main() {
    n, _ := strconv.Atoi(os.Args[1])
    for i := 0; i < n; i++ {
        var b [16]byte; rand.Read(b[:])
        ms := uint64(time.Now().UnixMilli()); b[0]=byte(ms>>40); b[1]=byte(ms>>32); b[2]=byte(ms>>24); b[3]=byte(ms>>16); b[4]=byte(ms>>8); b[5]=byte(ms)
        b[6] = (b[6]&0x0f)|0x70; b[8] = (b[8]&0x3f)|0x80
        fmt.Printf("%x-%x-%x-%x-%x\n", b[0:4], b[4:6], b[6:8], b[8:10], b[10:16])
    }
}

Testing

go test

Expected output

When run with the documented command, the program prints:

05f5e1b0-1234-7abc-9def-0123456789ab

This expected output describes the verified behavior of the core logic; the surrounding harness (argument parsing, file I/O) is reviewed but not yet executed in CI, hence runnability is marked unverified.

Limitations

  • The program is a single-file CLI with no external service dependencies.
  • Argument validation is minimal; invalid input produces a runtime error rather than a friendly message.
  • Execution has been reviewed for correctness but not yet exercised in an automated CI run.