sprint

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README ¶

sprint

Go library with lots of useful helpers having zero dependencies

🚀 Install

go get github.com/jastBytes/sprint

This library has no dependencies outside the Go standard library.

💡 Usage

You can import sprint using:

import (
    "github.com/jastBytes/sprint"
)

Documentation ¶

Index ¶

Constants ¶

View Source
const (
	Ki = 1024
	Mi = 1024 * Ki
	Gi = 1024 * Mi
	Ti = 1024 * Gi
	Pi = 1024 * Ti
)

See: http://en.wikipedia.org/wiki/Binary_prefix

Variables ¶

This section is empty.

Functions ¶

func DefaultIfEmpty ¶ added in v0.0.3

func DefaultIfEmpty(v string, d string) string

DefaultIfEmpty returns v if not empty otherwise d

func DefaultIfNil ¶

func DefaultIfNil[V any](val, def *V) *V

DefaultIfNil returns val if val is not nil, def otherwise

func Dehumanize ¶ added in v0.0.3

func Dehumanize(humanizedNumber string) (int64, error)

Dehumanize parses a string representation of a number in power of two and returns as number, e.g. 1, 5Mi, 10Gi.

func Hash ¶ added in v0.0.3

func Hash[T any](s T) ([]byte, error)

Hash returns a SHA256 hash of the given struct

func HashString ¶ added in v0.0.3

func HashString[T any](s T) (string, error)

Hash returns a SHA256 hash of the given struct as string

func Humanize ¶ added in v0.0.3

func Humanize(number int64) string

Humanize returns a string representation of the given number in power of two.

func PanicOnError ¶

func PanicOnError(err error)

PanicOnError panics if the given error is not nil DO NOT USE WITH DEFER

func PanicOnErrorFunc ¶

func PanicOnErrorFunc(f func() error)

PanicOnErrorFunc panics if the given function execution error is not nil

func ToPointer ¶

func ToPointer[V any](v V) *V

ToPointer returns a pointer to v

Types ¶

This section is empty.

Jump to

Keyboard shortcuts

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