A simple, extensible and incredible fast Golang library for generating and parsing ULIDs with full test coverage and mock support.
This library provides:
- A default ULID generator with deterministic time encoding and cryptographic randomness.
- Utilities to validate ULID format, decode timestamps, extract randomness, and format dates.
- 100% unit and feature tests.
- A mock implementation (
mock/ulid_mock.go
) to simplify testing your own code.
# Add the library as a dependency
go get github.com/not-empty/ulid-go-lib
Import the package and use the default generator:
import (
"fmt"
"log"
"github.com/not-empty/ulid-go-lib"
)
func main() {
gen := ulid.NewDefaultGenerator()
id, err := gen.Generate(0) // pass 0 for now = current time
if err != nil {
log.Fatal(err)
}
fmt.Println("ULID:", id)
}
See ./example/ulid_example.go
for a runnable demonstration of all public methods.
-
Unit tests: run the script
./test.sh
-
Coverage report: open the generated HTML
open ./test/coverage-unit.html
A mock implementation is provided in mock.ULIDMock
. To see it in action, run:
./mock.sh
Use mock.ULIDMock
in your tests to override any behavior of the ULID generator. To see the mock example look in ./mock/ulid_mock_test.go
This project is licensed under the GNU General Public License v3.0. See the LICENSE file for details.
Contribuite by submitting issues and pull requests. Feedback and improvements are always welcome.
Not Empty Foundation - Free codes, full minds