Library to generate MongoDB objectID's
$ objectid -h
Usage of objectid:
-format string
format of objectid: hex, base64 (default "hex")
-from-time string
create a new objectid from a date time (RFC3339, $(date -I), $(date -Ihours), $(date -d -Iminutes), $(date -Iseconds)
-n int
number of objectid to generate (default 1)
-separator string
separator between objectids (default "\n")
-to-time string
convert objectid to time
$ objectid
6435f4800000000000000000
$ objectid -format base64
ZiesvNpsbBz8QUGk
$ objectid -n 3
6435f4800000000000000000
6435f4800000000000000001
6435f4800000000000000002
$ objectid -from-time 2023-04-12
6435f4800000000000000000%
$ objectid -to-time 6435f4800000000000000000
2023-04-12 00:00:00 +0000 UTC
go get -u github.com/Ajnasz/objectid
import "github.com/Ajnasz/objectid"
func main() {
oid := objectid.New()
fmt.Printf("%s", oid)
}
go install github.com/Ajnasz/objectid/cmd/objectid
or
make build
bin/objectid