utils

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

this package hosts utilities that probably don't belong elsewhere. a utils package is fine. rule: nothing in this package can depend on any other package in this project.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CtxFireLoop

func CtxFireLoop(ctx context.Context, delay time.Duration, fn func())

CtxFireLoop blocks and fires the callback function on a tick. The callback function is fired first before the first delay.

func CtxFireLoopTicker

func CtxFireLoopTicker(ctx context.Context, ticker *time.Ticker, fn func())

CtxFireLoopTicker blocks and fires the callback function on a tick. The callback function is fired first before the first delay.

func CtxLoop

func CtxLoop(ctx context.Context, delay time.Duration, fn func())

CtxLoop blocks and fires the callback function on a tick.

func CtxLoopTicker

func CtxLoopTicker(ctx context.Context, ticker *time.Ticker, fn func())

CtxLoopTicker blocks and fires the callback function on a tick.

func EnsureDirForFile

func EnsureDirForFile(file string) error

EnsureDirForFile ensures that the specified file's parent directory exists.

func InterfaceSlice

func InterfaceSlice(any ...interface{}) []interface{}

Converts args to an interface slice using the following rules:

- Returns empty slice if no args are passed

  • For a single argument which is of a slice type, the slice is converted and returned.
  • For a single argument which is not a slice type, the value is returned within a single-element slice.

- For multiple arguments, returns a slice with all the args

Types

type AtomicBool

type AtomicBool int32

func (*AtomicBool) IsSet

func (b *AtomicBool) IsSet() bool

func (*AtomicBool) SetFalse

func (b *AtomicBool) SetFalse()

func (*AtomicBool) SetTrue

func (b *AtomicBool) SetTrue()

type JsonReader

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

JsonReader is a convenience type that is constructed with a type to be serialized using newJsonReader. it implements io.Reader and writes JSON bytes to the client. Useful for supplying a reader for the body of an http request. This allows the client to omit the extra step of encoding a struct into a byte slice and then passing a bytes.NewReader(b) to something expecting that reader.

func NewJsonReader

func NewJsonReader(val interface{}) *JsonReader

func (*JsonReader) Read

func (r *JsonReader) Read(p []byte) (n int, err error)

type Teardowns

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

Teardowns is meant to make it easy to chain teardown funcs and then have them execute in reverse order (like defer)

func (*Teardowns) Add

func (t *Teardowns) Add(fn func())

func (*Teardowns) Teardown

func (t *Teardowns) Teardown()

Jump to

Keyboard shortcuts

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