util

package
v0.0.0-...-5d153c6 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SIGHUP  = 0x1
	SIGINT  = 0x2
	SIGQUIT = 0x3
	SIGTERM = 0xF
)
View Source
const (
	TimeFormat = "2006-01-02T15:04:05.000Z"
)
View Source
const (
	// This is the canonical timestamp format.
	// Always UTC, lexigraphically sortable.  This is the best
	// timestamp format, accept no others.
	TimestampFormat = time.RFC3339Nano
)

Variables

View Source
var (
	LogInfo  = false
	LogDebug = false
)

Functions

func Backtrace

func Backtrace(size int) []string

Backtrace gathers a backtrace for the caller. Return a slice of up to N stack frames.

func Darwin

func Darwin() bool

func Debug

func Debug(arg string)

Verbosity level helps track down production issues:

-l debug

func Debugf

func Debugf(msg string, args ...interface{})

Verbosity level helps track down production issues:

-l debug

func DecodePrivateKey

func DecodePrivateKey(k []byte) (crypto.PrivateKey, error)

func DecodePublicKey

func DecodePublicKey(k []byte) (crypto.PublicKey, error)

func DumpError

func DumpError(err error)

func DumpProcessTrace

func DumpProcessTrace()

func DumpRequest

func DumpRequest(r *http.Request)

func EnsureChildShutdown

func EnsureChildShutdown(cmd *exec.Cmd, sig int)

func Epoch

func Epoch() time.Time

func Error

func Error(msg string, err error)

func FileExists

func FileExists(path string) (bool, error)

FileExists checks if given file exists

func GenerateKeys

func GenerateKeys() ([]byte, []byte)

generate an RSA public and private keypair

func Info

func Info(arg string)

Typical logging output, the default level

func Infof

func Infof(msg string, args ...interface{})

Typical logging output, the default level

func InitLogger

func InitLogger(level string)

func MemoryUsageMB

func MemoryUsageMB() uint64

func Nows

func Nows() string

func ParseTime

func ParseTime(str string) (time.Time, error)

func RandomInt63

func RandomInt63() (int64, error)

func RandomJid

func RandomJid() string

func Retryable

func Retryable(name string, count int, fn func() error) error

func Thens

func Thens(tim time.Time) string

func Warn

func Warn(arg string)

Uh oh, not good but not worthy of process death

func Warnf

func Warnf(msg string, args ...interface{})

Types

type Level

type Level int
const (
	InvalidLevel Level = iota - 1
	DebugLevel
	InfoLevel
	WarnLevel
	ErrorLevel
	FatalLevel
)

type SID

type SID struct {
	// Timestamp is the timestamp of the snowflake ID.
	Timestamp int64
	// Sequence is the sequence number of the snowflake ID.
	Sequence uint64
	// Field is the field value of the snowflake ID.
	Field uint64
}

SID is the parsed representation of a snowflake ID.

func Parse

func Parse(sid uint64) SID

Parse parses an existing snowflake ID

type Snowflake

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

func NewSnowflake

func NewSnowflake() *Snowflake

New returns a new snowflake.ID (max field value: 1023)

func (*Snowflake) NextID

func (id *Snowflake) NextID() uint64

func (*Snowflake) NextSID

func (id *Snowflake) NextSID() string

NextID returns a new snowflake ID.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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