uuid

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2024 License: MIT Imports: 14 Imported by: 0

README

uuid Go Reference Release Tests Go Report Card License

an alternative to the github.com/google/uuid package

Installation

go get -u github.com/malivvan/uuid

Usage

package main

import (
    "fmt"
    "github.com/malivvan/uuid"
)

func main() {
    // Generate a new UUID
    id, err := uuid.New("TYPE", 8)
    if err != nil {
        fmt.Println(err)
        return
    }
    fmt.Println(id)
}

Features

  • Type Prefix
  • Host Fingerprinting
  • Unix Timestamp
  • Data bytes with dynamic length
  • CRC Checksum

Structure

| TYPE-SYSTEMID-UNIXSECOND-XXXXXXXXXXXXXXXX-CHECKSUM |
|  4  |    4   |    4     |        N       |    4    | = N + 16 bytes

> TEST-C05FA96E-1720977041-F0ADF56596E2C4FB-188A8A03

Credits

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Func

func Func(t string, n int) func() (UUID, error)

func HostID

func HostID() (string, error)

HostID returns the platform specific machine id of the current host OS. Regard the returned id as "confidential" and consider using ProtectedID() instead.

func ProtectedHostID

func ProtectedHostID(appID string) (string, error)

ProtectedHostID returns a hashed version of the machine ID in a cryptographically secure way, using a fixed, application-specific key. Internally, this function calculates HMAC-SHA256 of the application ID, keyed by the machine ID.

Types

type UUID

type UUID []byte

func Decode

func Decode(s string) (UUID, error)

func New

func New(t string, n int) (UUID, error)

func Parse

func Parse(s string) (UUID, error)

func (UUID) CRC

func (uid UUID) CRC() []byte

func (UUID) Data

func (uid UUID) Data() []byte

Data returns the random data part of the UUID.

func (UUID) Encode

func (uid UUID) Encode() string

Encode returns a base64 encoded string representation of the UUID.

func (UUID) Host

func (uid UUID) Host() []byte

Host returns the host identifier part of the UUID.

func (UUID) Marshal

func (uid UUID) Marshal() []byte

Marshal returns a byte slice representation of the UUID.

func (UUID) String

func (uid UUID) String() string

String returns a string representation of the UUID in the following format: "AAAA-BBBBBBBBBBB-CCCCCC-DDDDDDDDDD-EEEE" where: - A is the type of the UUID - B is the host identifier - C are unix seconds - D is the random data - E is a crc32 checksum

func (UUID) Time

func (uid UUID) Time() time.Time

Time returns the time part of the UUID.

func (UUID) Type

func (uid UUID) Type() string

Type returns the type of the UUID.

Jump to

Keyboard shortcuts

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