uuidify

package module
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2025 License: MIT Imports: 10 Imported by: 0

README

uuidify-go — Fast UUID & ULID generation for Go apps

Official Go SDK for the UUIDify API.

Go Reference Go Report Card Release MIT License Go SDK Tests

Minimal, idiomatic Go client for generating UUIDv1/v4/v7 and ULID identifiers through UUIDify’s globally distributed API.


Install

go get github.com/ilkereroglu/uuidify-go

Usage

package main

import (
    "context"
    "fmt"
    "log"

    uuidify "github.com/ilkereroglu/uuidify-go"
)

func main() {
    client, err := uuidify.NewDefaultClient()
    if err != nil {
        log.Fatal(err)
    }

    id, err := client.UUIDv4(context.Background())
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println("UUID v4:", id)
}

Examples

Concrete demos live under examples/:

  • go run ./examples/uuid_v4 – fetch a single UUIDv4.
  • go run ./examples/uuid_v7_batch – batch-generate v7 identifiers.
  • go run ./examples/ulid – obtain a ULID. Each example uses context.Context, the default client, and the same error handling patterns you can reuse in your services.

Features

  • ✅ Drop-in NewDefaultClient() with overridable base URL, HTTP client, and User-Agent.
  • ⚡️ Fetch UUIDv1/v4/v7, ULID, or batch payloads with one call.
  • 🧵 Context-aware HTTP requests, perfect for microservices, CLIs, and serverless workloads.
  • 🎯 Typed error system (RequestError, APIError, DecodeError) for clean retries and observability.
  • 🧩 Generated directly from UUIDify’s OpenAPI spec, ensuring long-term compatibility.
  • 🧪 Backed by Go tooling (go test, go vet, CI) and production-friendly release workflow.

Why UUIDify

UUIDify is a latency-optimized unique identifier service built for modern Go developers. With this SDK you get:

  • A highly available UUID/ULID generator distributed across regions.
  • Predictable performance without maintaining your own randomness infrastructure.
  • Consistent REST semantics you can test locally and promote to production seamlessly.
  • OpenAPI-driven definitions to keep typed clients in sync across releases.

Service & Documentation

API Reference

License

MIT License © ilkereroglu

Documentation

Overview

Package uuidify provides primitives to interact with the openapi HTTP API.

Code generated by github.com/deepmap/oapi-codegen/v2 version v2.2.0 DO NOT EDIT.

Package uuidify provides primitives to interact with the openapi HTTP API.

Code generated by github.com/deepmap/oapi-codegen/v2 version v2.2.0 DO NOT EDIT.

Index

Constants

View Source
const (
	DefaultBaseURL = "https://api.uuidify.io"
)

Variables

This section is empty.

Functions

func NewGetRequest added in v0.2.0

func NewGetRequest(server string, params *GetParams) (*http.Request, error)

NewGetRequest generates requests for Get

Types

type APIError

type APIError struct {
	StatusCode int
	Message    string
}

APIError captures non-successful HTTP responses from the UUIDify API.

func (*APIError) Error

func (e *APIError) Error() string

type Client

type Client struct {
	// The endpoint of the server conforming to this interface, with scheme,
	// https://api.deepmap.com for example. This can contain a path relative
	// to the server, such as https://api.deepmap.com/dev-test, and all the
	// paths in the swagger spec will be appended to the server.
	Server string

	// Doer for performing requests, typically a *http.Client with any
	// customized settings, such as certificate chains.
	Client HttpRequestDoer

	// A list of callbacks for modifying requests which are generated before sending over
	// the network.
	RequestEditors []RequestEditorFn
}

Client which conforms to the OpenAPI3 specification for this service.

func NewClient

func NewClient(server string, opts ...ClientOption) (*Client, error)

Creates a new Client, with reasonable defaults

func NewDefaultClient added in v0.6.0

func NewDefaultClient(opts ...ClientOption) (*Client, error)

NewDefaultClient creates a client preconfigured with the public API endpoint.

func (*Client) Get added in v0.2.0

func (c *Client) Get(ctx context.Context, params *GetParams, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) ULID

func (c *Client) ULID(ctx context.Context) (string, error)

ULID fetches a ULID value.

func (*Client) ULIDBatch

func (c *Client) ULIDBatch(ctx context.Context, count int) ([]string, error)

ULIDBatch fetches multiple ULIDs.

func (*Client) UUIDBatch

func (c *Client) UUIDBatch(ctx context.Context, version string, count int) ([]string, error)

UUIDBatch fetches multiple UUIDs of the given version.

func (*Client) UUIDv1

func (c *Client) UUIDv1(ctx context.Context) (string, error)

UUIDv1 fetches a UUID v1 value.

func (*Client) UUIDv4

func (c *Client) UUIDv4(ctx context.Context) (string, error)

UUIDv4 fetches a UUID v4 value.

func (*Client) UUIDv7

func (c *Client) UUIDv7(ctx context.Context) (string, error)

UUIDv7 fetches a UUID v7 value.

type ClientInterface added in v0.2.0

type ClientInterface interface {
	// Get request
	Get(ctx context.Context, params *GetParams, reqEditors ...RequestEditorFn) (*http.Response, error)
}

The interface specification for the client above.

type ClientOption

type ClientOption func(*Client) error

ClientOption allows setting custom parameters during construction

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL overrides the baseURL.

func WithHTTPClient

func WithHTTPClient(doer HttpRequestDoer) ClientOption

WithHTTPClient allows overriding the default Doer, which is automatically created using http.Client. This is useful for tests.

func WithRequestEditorFn added in v0.2.0

func WithRequestEditorFn(fn RequestEditorFn) ClientOption

WithRequestEditorFn allows setting up a callback function, which will be called right before sending the request. This can be used to mutate the request.

func WithUserAgent

func WithUserAgent(ua string) ClientOption

WithUserAgent ensures every request carries the provided User-Agent header.

type ClientWithResponses added in v0.2.0

type ClientWithResponses struct {
	ClientInterface
}

ClientWithResponses builds on ClientInterface to offer response payloads

func NewClientWithResponses added in v0.2.0

func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error)

NewClientWithResponses creates a new ClientWithResponses, which wraps Client with return type handling

func (*ClientWithResponses) GetWithResponse added in v0.2.0

func (c *ClientWithResponses) GetWithResponse(ctx context.Context, params *GetParams, reqEditors ...RequestEditorFn) (*GetResponse, error)

GetWithResponse request returning *GetResponse

type ClientWithResponsesInterface added in v0.2.0

type ClientWithResponsesInterface interface {
	// GetWithResponse request
	GetWithResponse(ctx context.Context, params *GetParams, reqEditors ...RequestEditorFn) (*GetResponse, error)
}

ClientWithResponsesInterface is the interface specification for the client with responses above.

type DecodeError

type DecodeError struct {
	Err error
}

DecodeError wraps errors that occur while decoding API responses.

func (*DecodeError) Error

func (e *DecodeError) Error() string

func (*DecodeError) Unwrap

func (e *DecodeError) Unwrap() error

type GetParams added in v0.2.0

type GetParams struct {
	// Algorithm Generator algorithm selection
	Algorithm *GetParamsAlgorithm `form:"algorithm,omitempty" json:"algorithm,omitempty"`

	// Version UUID version.
	// When algorithm=ulid, version is ignored and ULIDs are produced.
	Version *GetParamsVersion `form:"version,omitempty" json:"version,omitempty"`

	// Count Number of identifiers to generate.
	Count *int `form:"count,omitempty" json:"count,omitempty"`

	// Format Response format.
	// - `json` → default structured JSON
	// - `text` → newline-delimited plaintext output
	Format *GetParamsFormat `form:"format,omitempty" json:"format,omitempty"`
}

GetParams defines parameters for Get.

type GetParamsAlgorithm added in v0.2.0

type GetParamsAlgorithm string

GetParamsAlgorithm defines parameters for Get.

const (
	GetParamsAlgorithmUlid GetParamsAlgorithm = "ulid"
	GetParamsAlgorithmUuid GetParamsAlgorithm = "uuid"
)

Defines values for GetParamsAlgorithm.

type GetParamsFormat added in v0.2.0

type GetParamsFormat string

GetParamsFormat defines parameters for Get.

const (
	Json GetParamsFormat = "json"
	Text GetParamsFormat = "text"
)

Defines values for GetParamsFormat.

type GetParamsVersion added in v0.2.0

type GetParamsVersion string

GetParamsVersion defines parameters for Get.

const (
	GetParamsVersionUlid GetParamsVersion = "ulid"
	GetParamsVersionV1   GetParamsVersion = "v1"
	GetParamsVersionV4   GetParamsVersion = "v4"
	GetParamsVersionV7   GetParamsVersion = "v7"
)

Defines values for GetParamsVersion.

type GetResponse added in v0.2.0

type GetResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *struct {
		// contains filtered or unexported fields
	}
	JSON400 *struct {
		Error *string `json:"error,omitempty"`
	}
}

func ParseGetResponse added in v0.2.0

func ParseGetResponse(rsp *http.Response) (*GetResponse, error)

ParseGetResponse parses an HTTP response from a GetWithResponse call

func (GetResponse) Status added in v0.2.0

func (r GetResponse) Status() string

Status returns HTTPResponse.Status

func (GetResponse) StatusCode added in v0.2.0

func (r GetResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type HttpRequestDoer added in v0.2.0

type HttpRequestDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

Doer performs HTTP requests.

The standard http.Client implements this interface.

type RequestEditorFn added in v0.2.0

type RequestEditorFn func(ctx context.Context, req *http.Request) error

RequestEditorFn is the function signature for the RequestEditor callback function

type RequestError

type RequestError struct {
	Err error
}

RequestError wraps lower-level request construction or transport errors.

func (*RequestError) Error

func (e *RequestError) Error() string

func (*RequestError) Unwrap

func (e *RequestError) Unwrap() error

Directories

Path Synopsis
examples
ulid command
uuid_v4 command
uuid_v7_batch command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL