Mini-app to showcase differences between id generators

This commit is contained in:
Melody Becker 2025-06-17 16:48:07 +02:00
parent e317da1b66
commit 67be27aebe
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI
3 changed files with 43 additions and 0 deletions

41
cmd/sample-id-gen/main.go Normal file
View file

@ -0,0 +1,41 @@
package main
import (
"flag"
"fmt"
"github.com/google/uuid"
"github.com/nrednav/cuid2"
"github.com/rs/xid"
)
var flagGenerator = flag.String(
"generator",
"xid",
"Which generator to showcase. Options: xid, cuid, uuid. Defaults to xid",
)
func main() {
flag.Parse()
generator := "xid"
switch *flagGenerator {
case "uuid":
generator = "uuid"
case "cuid":
generator = "cuid"
}
fmt.Printf("Generator used: %s\n", generator)
var gen func() string
switch generator {
case "xid":
gen = func() string { return xid.New().String() }
case "uuid":
gen = uuid.NewString
case "cuid":
gen = cuid2.Generate
}
fmt.Println("Generating 10 ids")
for range 10 {
fmt.Println(gen())
}
}