Skip to content

ULID Golang Library: A simple, extensible and incredible fast Golang library for generating and parsing ULIDs with full test coverage and mock support.

Notifications You must be signed in to change notification settings

not-empty/ulid-go-lib

Repository files navigation

ULID Golang Library

A simple, extensible and incredible fast Golang library for generating and parsing ULIDs with full test coverage and mock support.


Description

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.

Installation

# Add the library as a dependency
go get github.com/not-empty/ulid-go-lib

Usage

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)
}

Example

See ./example/ulid_example.go for a runnable demonstration of all public methods.

Running Tests

  • Unit tests: run the script

    ./test.sh
  • Coverage report: open the generated HTML

    open ./test/coverage-unit.html

Mocking

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

License

This project is licensed under the GNU General Public License v3.0. See the LICENSE file for details.

Contributing

Contribuite by submitting issues and pull requests. Feedback and improvements are always welcome.


Not Empty Foundation - Free codes, full minds

About

ULID Golang Library: A simple, extensible and incredible fast Golang library for generating and parsing ULIDs with full test coverage and mock support.

Resources

Stars

Watchers

Forks

Packages

No packages published