logid

package
v2.12.8 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const IPUnknown = "AAAAAAA"

IPUnknown represents unknown IP address.

Variables

This section is empty.

Functions

func Gen

func Gen() string

Gen generates a new log ID string using the default generator.

func SetDefault

func SetDefault(gen Generator)

SetDefault changes the default generator.

The default generator may be changed by the main program, but generally library code shall not call this function.

Types

type Generator

type Generator interface {

	// Gen generates a new log ID string, it should always return
	// a valid log ID, and don't generate duplicate log IDs.
	Gen() string
}

type Info

type Info interface {
	Valid() bool
	Version() byte
	String() string
}

Info holds parsed information of a log ID string.

func Decode

func Decode(s string) (info Info)

Decode decodes a log ID string and returns the parsed information,

type V1Gen added in v2.12.0

type V1Gen struct {
	// contains filtered or unexported fields
}

V1Gen is a v1 log ID generator.

A v1 log ID is consisted of the following parts:

  • 17 bytes milli timestamp
  • 16 bytes hash of the machine ID of current host if available, else 16 bytes random data
  • 10 bytes random data, with 1 bit to mark UTC timezone
  • 1 byte version flag "1"

func NewV1Gen

func NewV1Gen() *V1Gen

NewV1Gen creates a new v1 log ID generator.

func (*V1Gen) Gen added in v2.12.0

func (p *V1Gen) Gen() string

Gen generates a new log ID string.

func (*V1Gen) UseUTC added in v2.12.0

func (p *V1Gen) UseUTC() *V1Gen

UseUTC sets the generator to format timestamp with location time.UTC. By default, it formats timestamp with location time.Local.

type V1Info added in v2.12.0

type V1Info interface {
	Info
	Time() time.Time
	MachineID() string
	Random() string
}

type V2Gen added in v2.12.0

type V2Gen struct {
	// contains filtered or unexported fields
}

V2Gen is a v2 log ID generator.

A v2 log ID is consisted by the following parts:

  • 17 bytes milli timestamp
  • 26 bytes IPv6 address, or 7 bytes IPv4 address, in base32 form
  • 10 bytes random data, with 1 bit to mark UTC timezone
  • 1 byte version flag "2"

func NewV2Gen

func NewV2Gen(ip net.IP) *V2Gen

NewV2Gen creates a new v2 log ID generator.

func (*V2Gen) Gen added in v2.12.0

func (p *V2Gen) Gen() string

Gen generates a new log ID string.

func (*V2Gen) UseUTC added in v2.12.0

func (p *V2Gen) UseUTC() *V2Gen

UseUTC sets the generator to format timestamp with location time.UTC. By default, it formats timestamp with location time.Local.

type V2Info added in v2.12.0

type V2Info interface {
	Info
	Time() time.Time
	IP() net.IP
	Random() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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