util

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2022 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyOnType

func ApplyOnType[T any](t *T, tFuncs []func(*T))

ApplyOnType takes the address of type `t` and an array of functions that do something with this type, and applies the functions to the type.

func FTWSTHf

func FTWSTHf(formatString string, vals ...interface{}) string

FTWSTHf adds a message at the end of the given string, indicating the developer's frustration. It takes a format string as its main input so go nuts.

func IsNonNilPointer

func IsNonNilPointer(v interface{}) bool

func JSONResponse

func JSONResponse(w http.ResponseWriter, out any, optfuncs ...jSONRespOptFunc)

JSONResponse marshalls the argument `out` into JSON and response on the provided ResponseWriter. Options can be provided to further modidy the response.

func Line

func Line(x float64) float64

func LogOnError

func LogOnError(err error, msg string)

func Map

func Map[T Numeric](input, inputStart, inputEnd, outputStart, outputEnd T) T

func Must

func Must(err error, msgs ...string)

Must is a quick way to panic in programs if an error exists with a helpful message being printed. It helps avoid having check for errors at every step of a top-level program.

func NewImageReaderFromUrl

func NewImageReaderFromUrl(endpoint string) (io.ReadCloser, error)

func OptimisticAtoi

func OptimisticAtoi(inp string) int

OptimisticAtoi is the, well, optimistic version of the stdlib's Atoi function. It assumes the conversion will succeed for sure. Don't use in production.

func RandNegOneOne

func RandNegOneOne() float64

func ReadBodyAsString

func ReadBodyAsString(r *http.Request) string

func Sample

func Sample[T any](slice []T) T

func Sigmoid

func Sigmoid(x float64) float64

func Sign

func Sign[T Numeric](inp T) T

func WithStatusCode

func WithStatusCode(statusCode int) jSONRespOptFunc

WithStatusCode allows modifying the status code of the JSON response. The default is 200 OK.

Types

type GenericMap

type GenericMap map[string]interface{}

type Numeric

type Numeric interface {
	constraints.Signed | constraints.Float
}

Jump to

Keyboard shortcuts

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