util

package
v0.0.0-...-0eb8f9d Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Checksum

func Checksum[T any](v T) string

Checksum returns the md5 checksum of the given v when encoded as json

func FiniteValueChannel

func FiniteValueChannel[T any](val ...T) <-chan T

FiniteValueChannel returns a new read-only buffered channel with all the provided values already pushed into it. The channel returned is closed and allows no further writes.

func Json

func Json[T any](src *T, sink io.Writer) error

Json encodes the given source object using encoding/json to the given sink.

func Must

func Must[T any](v T, err error) T

func RandUint64

func RandUint64(n uint64) uint64

RandUint64 returns a secure-random uint64 value generated using crypto/rand

func ToPtr

func ToPtr[T any](v T) *T

ToPtr returns a a pointer to v

func Zstd

func Zstd[T any](src *T, sink io.Writer) error

Zstd encodes the given source object using encoding/json and compresses using zstd before writing to given sink.

Types

type HandlerFunc

type HandlerFunc[I any, O any] func(context.Context, I) (*O, error)

HandlerFunc takes care of boilerplate details around handling requests and responses.

func (HandlerFunc[I, O]) ServeHTTP

func (h HandlerFunc[I, O]) ServeHTTP(res http.ResponseWriter, req *http.Request)

type StreamingHandlerFunc

type StreamingHandlerFunc[I any] func(context.Context, http.ResponseWriter, I) error

StreamingHandlerFunc takes care of boilerplate details around handling requests where responses can be sent as a stream of 0 or more objects. It exposes the http.ResponseWriter to the implementer.

func (StreamingHandlerFunc[I]) ServeHTTP

func (h StreamingHandlerFunc[I]) ServeHTTP(res http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

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