util

package
v0.0.0-...-fd00b2c Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 12 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 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

Types

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
Package usock implements a wrapper around the unix(7) SCM_RIGHTS API, which allows processes to exchange file handles over a unix(7) control socket.
Package usock implements a wrapper around the unix(7) SCM_RIGHTS API, which allows processes to exchange file handles over a unix(7) control socket.

Jump to

Keyboard shortcuts

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