util

package
v0.0.0-...-ca8de47 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsolutePath

func AbsolutePath(dir string, path string) string

func AddContentDisposition

func AddContentDisposition(w http.ResponseWriter, filename string)

func AddContentDispositionSong

func AddContentDispositionSong(w http.ResponseWriter, metadata, filename string)

func ChangeRequestMethod

func ChangeRequestMethod(r *http.Request, method string) *http.Request

func IsHTMX

func IsHTMX(r *http.Request) bool

IsHTMX checks if a request was made by HTMX through the Hx-Request header

func OneOff

func OneOff[T any](ctx context.Context, fn StreamFn[T]) (T, error)

OneOff creates a stream through fn and returns the first value received after which it closes the stream. Should be used where you only need a very sporadic value that is supplied by a streaming API.

func RedirectBack

func RedirectBack(r *http.Request) *http.Request

func RedirectToServer

func RedirectToServer(w http.ResponseWriter, r *http.Request) error

RedirectToServer looks up the http.Server associated with this request and calls ServeHTTP again

func ReduceHasLeftover

func ReduceHasLeftover[T any](s []T, step int) bool

func ReduceWithStep

func ReduceWithStep[T any](s []T, step int) []T

func RestoreOrListen

func RestoreOrListen(store *fdstore.Store, name string, network, addr string) (net.Listener, []byte, error)

RestoreOrListen tries to restore a listener with the name given from the store given. If any error occurs it instead just calls net.Listen with the provided arguments network and addr

func Signal

func Signal(signals ...os.Signal) <-chan os.Signal

Signal returns a channel that will receive the signals given as arguments, similar to signal.Notify but creating the channel for you on the fly.

Types

type CallbackTimer

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

func NewCallbackTimer

func NewCallbackTimer(callback func()) *CallbackTimer

func (*CallbackTimer) Start

func (tc *CallbackTimer) Start(timeout time.Duration)

Start starts a timer with the timeout given, if a timer is already running it is stopped and a new timer is created

func (*CallbackTimer) Stop

func (tc *CallbackTimer) Stop() bool

Stop stops the current timer if one exists

type Map

type Map[K, V any] struct {
	// contains filtered or unexported fields
}

func (*Map[K, V]) CompareAndDelete

func (m *Map[K, V]) CompareAndDelete(key K, old V) (deleted bool)

func (*Map[K, V]) CompareAndSwap

func (m *Map[K, V]) CompareAndSwap(key K, old V, new V) bool

func (*Map[K, V]) Delete

func (m *Map[K, V]) Delete(key K)

func (*Map[K, V]) Load

func (m *Map[K, V]) Load(key K) (value V, ok bool)

func (*Map[K, V]) LoadAndDelete

func (m *Map[K, V]) LoadAndDelete(key K) (value V, loaded bool)

func (*Map[K, V]) LoadOrStore

func (m *Map[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)

func (*Map[K, V]) Range

func (m *Map[K, V]) Range(fn func(key K, value V) bool)

func (*Map[K, V]) Store

func (m *Map[K, V]) Store(key K, value V)

func (*Map[K, V]) Swap

func (m *Map[K, V]) Swap(key K, value V) (previous V, loaded bool)

type StreamCallbackFn

type StreamCallbackFn[T any] func(context.Context, T)

type StreamFn

type StreamFn[T any] func(context.Context) (eventstream.Stream[T], error)

type TypedValue

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

func NewTypedValue

func NewTypedValue[T any](initial T) *TypedValue[T]

func (*TypedValue[T]) Load

func (tv *TypedValue[T]) Load() T

func (*TypedValue[T]) Store

func (tv *TypedValue[T]) Store(new T)

func (*TypedValue[T]) Swap

func (tv *TypedValue[T]) Swap(newv T) (old T)

type Value

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

func StreamValue

func StreamValue[T any](ctx context.Context, fn StreamFn[T], callbackFn ...StreamCallbackFn[T]) *Value[T]

StreamValue opens the stream created by StreamFn and calls any callbackFn given everytime a new value is returned by the stream. StreamValue also stores the last received value, accessable by calling .Latest

func (*Value[T]) Latest

func (v *Value[T]) Latest() T

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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