util

package
v0.0.0-...-5be94a9 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const HeaderContentDisposition = "Content-Disposition"

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 NewZerologAttributes

func NewZerologAttributes(logger zerolog.Logger) func(next http.Handler) http.Handler

NewZerologAttributes aggregates a bunch of zerolog/hlog middleware into a single one

hlog.NewHandler(*logger)
hlog.RemoteAddrHandler("ip")
hlog.UserAgentHandler("user_agent")
hlog.URLHandler("url")
hlog.MethodHandler("method")
hlog.ProtoHandler("protocol")
hlog.CustomHeaderHandler("is_htmx", "Hx-Request")
hlog.RefererHandler("referer")

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) (nr *http.Request, success bool)

func RedirectPath

func RedirectPath(r *http.Request, newpath string) *http.Request

RedirectPath modifies r's path to the newpath given

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 ZerologLoggerFunc

func ZerologLoggerFunc(r *http.Request, status, size int, duration time.Duration)

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]) Clear

func (m *Map[K, V]) Clear()

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 StreamValuer

type StreamValuer[T any] interface {
	Latest() T
}

func NewStatusValue

NewStatusValue is a silly special cased *Value that updates the statuses listener count before returning the status, since just listening to CurrentStatus by itself will only have listeners update when a song change occurs

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 NewStaticValue

func NewStaticValue[T any](static T) *Value[T]

NewStaticValue returns a Value that stores the static variable, should really only be used in testing

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, accessible 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