handy

package module
v0.0.0-...-022d51f Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2022 License: MIT Imports: 10 Imported by: 17 modules, 23 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Handy

GitHub Go Reference Go Report Card Go GitHub go.mod Go version (branch)

Documentation

Index

Constants

View Source
const Day = time.Hour * 24
View Source
const MaxInt = int(MaxUint >> 1)

MaxInt is max int value

View Source
const MaxUint = ^uint(0)

MaxUint is max uint value

View Source
const Month = Day * 30
View Source
const UintptrSize = unsafe.Sizeof(uintptr(0))

UintptrSize is memory size of uintptr

View Source
const Week = Day * 7
View Source
const Year = Day * 365

Variables

View Source
var ErrAssertion = errors.New("assertion")

ErrAssertion is an assertion failed error

Functions

func Assert

func Assert(value bool, WhatWillPanic ...interface{})

Assert panic WhatWillPanic for ErrAssertion if value is false

func Bits

func Bits[T constraints.Integer](n T) int

Bits return bit size of any integer

func Box

func Box(fn func()) (recovered interface{})

Box call fn and recover a panic and returns recovered value

func Cast

func Cast[T any](t interface{}) T

Cast [T any] casts interface{} to T

func Catch

func Catch[T any](fn func(recovered T))

Catch call fn with recovered value is it's not nil

func DeRef

func DeRef[T any](ptr uintptr) T

DeRef returns the value pointer points to

func Equal

func Equal(a, b any) bool

func Just

func Just(closable func() error)

func Loop

func Loop()

func MustMarshalBinary

func MustMarshalBinary(value encoding.BinaryMarshaler) []byte

func MustMarshalText

func MustMarshalText(value encoding.TextMarshaler) []byte

func Rand

func Rand(length int) []byte

func Recover

func Recover[T any]() T

func Ref

func Ref[T any](value *T) uintptr

Ref returns a uintptr points to the value

func Stop

func Stop(t *time.Timer)

func Throw

func Throw(values ...interface{})

Throw panics if any of values is not nil

Types

type ByNames

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

ByNames force struct to init with fields name

type Empty

type Empty = struct{}

Empty is a zero size struct

func N

func N(times int) []Empty

N is utility for ranges

type NoCompare

type NoCompare struct {
	NotComparable [0]func() `json:"-"`
}

NoCompare prevents struct to be compared

type NoCopy

type NoCopy Empty

NoCopy warns in go vet to struct be copied

func (*NoCopy) Lock

func (*NoCopy) Lock()

Lock does nothing

func (*NoCopy) Unlock

func (*NoCopy) Unlock()

Unlock does nothing

Jump to

Keyboard shortcuts

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