logid

package
v2.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// IPUnknown represents unknown IP address.
	IPUnknown = "00000000000000000000000000000000"
)

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
}

func NewV1Gen

func NewV1Gen() Generator

NewV1Gen creates a new v1 log ID generator.

A v1 log ID is consisted of the following parts:

  • 1 byte version flag "1"
  • 9 bytes milli timestamp, in base32 form
  • 16 bytes hash of the machine ID of current host if available, else 16 bytes random data
  • 8 bytes random data

func NewV2Gen

func NewV2Gen(ip net.IP) Generator

NewV2Gen creates a new v2 log ID generator.

A v2 log ID is consisted of the following parts:

  • 1 byte version flag "2"
  • 9 bytes milli timestamp, in base32 form
  • 32 bytes IP address, in hex form
  • 5 bytes random data

type Info

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

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.

func (Info) IP

func (i Info) IP() net.IP

IP returns the IP information of the log ID if available, else it returns nil.

func (Info) Random

func (i Info) Random() string

Random returns the random part of the log ID if available, else it returns an empty string.

func (Info) String

func (i Info) String() string

String formats the log ID's information to string.

func (Info) Time

func (i Info) Time() time.Time

Time returns the time information of the log ID if available, else it returns a zero time.Time{}.

func (Info) Valid

func (i Info) Valid() bool

Valid tells whether the info holds valid log ID information.

func (Info) Version

func (i Info) Version() string

Version returns the log ID's version.

Jump to

Keyboard shortcuts

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