utils

package
v0.0.0-...-0244bd9 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 27 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrObjectNotFound = errors.New("object not found")
	ErrNotImplemented = errors.New("not implemented")
)
View Source
var ErrInvalidIP = errors.New("invalid IP")

Functions

func CanonicalAddr

func CanonicalAddr(addr netip.Addr) netip.Addr

CanonicalAddr returns the IPv4 form of an IPv4-mapped IPv6 address and strips any IPv6 zone.

func CanonicalPrefix

func CanonicalPrefix(pfx netip.Prefix) (netip.Prefix, error)

func EnsurePrefix

func EnsurePrefix(s string, prefix string) string

func EnsureSuffix

func EnsureSuffix(s string, suffix string) string

func FromQuery

func FromQuery[T any](query url.Values) (*T, error)

func FromRequest

func FromRequest[T any](r *http.Request) (*T, error)

func Hostname

func Hostname() string

func HostnameOrErr

func HostnameOrErr(allowPanic ...bool) (string, error)

func IPKeyToPrefix

func IPKeyToPrefix(ip string) (netip.Prefix, error)

func IsIn

func IsIn[T comparable](first T, slice ...T) bool

func Parse

func Parse[T Parsed](s string) (result T, err error)

func ProbeInto

func ProbeInto(ctx context.Context, path string, res any, args map[string]any) error

func Query

func Query[T any](obj T) url.Values

func RandString

func RandString(n int) string

func RandToken

func RandToken(n int) (string, error)

func RegisterQueryConverter

func RegisterQueryConverter[T any](encode func(v reflect.Value) string, decode func(s string) reflect.Value)

func TimeTrack

func TimeTrack(f func()) (d time.Duration)

Types

type ContextKey

type ContextKey struct {
	Name string
}

func (*ContextKey) String

func (k *ContextKey) String() string

type FFMpegProbe

type FFMpegProbe struct {
	Format struct {
		Duration       string `json:"duration"`
		Filename       string `json:"filename"`
		NbStreams      int    `json:"nb_streams"`
		NbPrograms     int    `json:"nb_programs"`
		FormatName     string `json:"format_name"`
		FormatLongName string `json:"format_long_name"`
		StartTime      string `json:"start_time"`
		Size           string `json:"size"`
		BitRate        string `json:"bit_rate"`
		ProbeScore     int    `json:"probe_score"`
	} `json:"format"`
}

func Probe

func Probe(ctx context.Context, path string, args map[string]any) (*FFMpegProbe, error)

func (FFMpegProbe) Duration

func (p FFMpegProbe) Duration() (float64, error)

type FullyHidden

type FullyHidden = HiddenString[starHider]

type HiddenString

type HiddenString[T StringHider] string

func (HiddenString[T]) MarshalJSON

func (c HiddenString[T]) MarshalJSON() ([]byte, error)

func (HiddenString[T]) String

func (c HiddenString[T]) String() string

type IPTree

type IPTree[V any] struct {
	// contains filtered or unexported fields
}

func NewIPTree

func NewIPTree[V any]() *IPTree[V]

func (*IPTree[V]) Delete

func (t *IPTree[V]) Delete(ipCidr string) error

func (*IPTree[V]) Insert

func (t *IPTree[V]) Insert(ipCidr string, val V) error

func (*IPTree[V]) Lookup

func (t *IPTree[V]) Lookup(ip netip.Addr) (V, bool)

func (*IPTree[V]) LookupString

func (t *IPTree[V]) LookupString(ip string) (V, bool)

func (*IPTree[V]) PutIPs

func (t *IPTree[V]) PutIPs(val V, ips ...netip.Addr) error

func (*IPTree[V]) PutPrefixes

func (t *IPTree[V]) PutPrefixes(val V, pfxs ...netip.Prefix) error

type IPTreeSet

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

func NewIPTreeSet

func NewIPTreeSet() *IPTreeSet

func (*IPTreeSet) Delete

func (s *IPTreeSet) Delete(ipCidrs ...string) error

func (*IPTreeSet) Len

func (s *IPTreeSet) Len() int

func (*IPTreeSet) Match

func (s *IPTreeSet) Match(ip netip.Addr) bool

func (*IPTreeSet) Put

func (s *IPTreeSet) Put(ipCidrs ...string) error

func (*IPTreeSet) PutIPs

func (s *IPTreeSet) PutIPs(ips ...netip.Addr) error

func (*IPTreeSet) PutPrefixes

func (s *IPTreeSet) PutPrefixes(pfxs ...netip.Prefix) error

type Parsed

type Parsed interface {
	constraints.Integer | constraints.Unsigned | constraints.Float | ~bool | ~string
}

type PartiallyHidden

type PartiallyHidden = HiddenString[partialHider]

type ResponseWriter

type ResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

ResponseWriter wrapper to allows middleware to set headers without worrying about the response header being written already.

func UnwrapResponseWriter

func UnwrapResponseWriter(w http.ResponseWriter) (rw *ResponseWriter, ok bool)

Unwrap the response writer

func WrapResponseWriter

func WrapResponseWriter(w http.ResponseWriter) *ResponseWriter

func (*ResponseWriter) Flush

func (rw *ResponseWriter) Flush() (int, error)

Flush the response

func (*ResponseWriter) Hijack

func (rw *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)

func (*ResponseWriter) StatusCode

func (w *ResponseWriter) StatusCode() int

type Set

type Set[K comparable] struct {
	// contains filtered or unexported fields
}

Set implements a hashset, using the hashmap as the underlying storage.

func NewSet

func NewSet[K comparable]() Set[K]

New returns an empty hashset.

func SetDiff

func SetDiff[K comparable](a, b Set[K]) Set[K]

func SetIntersection

func SetIntersection[K comparable](a, b Set[K]) (intersection Set[K])

func SetOf

func SetOf[K comparable](vals ...K) Set[K]

Of returns a new hashset initialized with the given 'vals'

func SetUnion

func SetUnion[K comparable](a, b Set[K]) Set[K]

func (*Set[K]) Clear

func (s *Set[K]) Clear()

Clear ...

func (Set[K]) Each

func (s Set[K]) Each(fn func(key K))

Each calls 'fn' on every item in the set in no particular order.

func (Set[K]) Empty

func (s Set[K]) Empty() bool

Empty ...

func (Set[K]) Has

func (s Set[K]) Has(val K) bool

Has returns true only if 'val' is in the set.

func (Set[K]) Iter

func (s Set[K]) Iter() iter.Seq[K]

func (Set[K]) Len

func (s Set[K]) Len() int

Size returns the number of elements in the set.

func (Set[K]) Put

func (s Set[K]) Put(vals ...K)

Put adds 'val' to the set.

func (Set[K]) Remove

func (s Set[K]) Remove(vals ...K)

Remove removes 'val' from the set.

func (Set[K]) ToSlice

func (s Set[K]) ToSlice() []K

type StringHider

type StringHider interface {
	Hide(string) string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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