https://github.com/ajnasz/objectid
Go library to generate MongoDB objectid
https://github.com/ajnasz/objectid
go go-package mongodb mongodb-objectid objectid package
Last synced: 6 months ago
JSON representation
Go library to generate MongoDB objectid
- Host: GitHub
- URL: https://github.com/ajnasz/objectid
- Owner: Ajnasz
- License: mit
- Created: 2023-06-12T07:09:00.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-04-23T12:44:36.000Z (about 2 years ago)
- Last Synced: 2024-04-29T21:15:19.797Z (about 2 years ago)
- Topics: go, go-package, mongodb, mongodb-objectid, objectid, package
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ObjectID
Library to generate MongoDB objectID's
[](https://goreportcard.com/report/github.com/Ajnasz/objectid)
[](https://pkg.go.dev/mod/github.com/Ajnasz/objectid)
## Command usage
```
$ 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
```
### Generate object id
```sh
$ objectid
6435f4800000000000000000
```
### Generate object id in base64
```sh
$ objectid -format base64
ZiesvNpsbBz8QUGk
```
### Generate multiple object id
```sh
$ objectid -n 3
6435f4800000000000000000
6435f4800000000000000001
6435f4800000000000000002
```
### Object id from time
```sh
$ objectid -from-time 2023-04-12
6435f4800000000000000000%
```
### Object id to time
```sh
$ objectid -to-time 6435f4800000000000000000
2023-04-12 00:00:00 +0000 UTC
```
## Library Usage
```sh
go get -u github.com/Ajnasz/objectid
```
```go
import "github.com/Ajnasz/objectid"
func main() {
oid := objectid.New()
fmt.Printf("%s", oid)
}
```
## CLI
### Install the cli tool
```sh
go install github.com/Ajnasz/objectid/cmd/objectid
```
or
```sh
make build
bin/objectid
```