aliU

package module
v0.3.14 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

https://github.com/NYTimes/gziphandler

Index

Constants

View Source
const DEFAULT_QVALUE = 1.0

The default qvalue to assign to an encoding if no explicit qvalue is set. This is actually kind of ambiguous in RFC 2616, so hopefully it's correct. The examples seem to indicate that it is.

Variables

This section is empty.

Functions

func ChunkString added in v0.2.4

func ChunkString(s string, size int) []string

ChunkString splits a string into chunks of the given size or smaller

func CleanString added in v0.3.13

func CleanString(in string) string

func ContainsString

func ContainsString(s string, a []string) bool

func ContentTypeFromFileName

func ContentTypeFromFileName(filename string) (string, error)

func CreateDirectoryIfNotExists added in v0.3.7

func CreateDirectoryIfNotExists(path string) (bool, error)

func DayStr added in v0.2.2

func DayStr(t time.Time) string

func DotProductDistance added in v0.3.8

func DotProductDistance(a, b []float64) (float64, error)

func DotProductSimilarity added in v0.3.8

func DotProductSimilarity(a, b []float64) (float64, error)

func DotX

func DotX(a []float64, b float64) []float64

func DotXX

func DotXX(a [][]float64, b float64) [][]float64

func ExistsOnDisk

func ExistsOnDisk(path string) (bool, error)

func FancyRandStr

func FancyRandStr(length int) string

func FastFail added in v0.2.2

func FastFail(failure string, args ...int)

FastFail is a GomegaFailHandler that, when run with `go test -failfast` , fails immidiately and halts other long running tests prints the line number of the test that failed from conversation with @onsi https://github.com/onsi/gomega/issues/660 this makes it possible to fail fast and not wait for all the tests to finish if they are going to fail usage: in your test, as the first line of the test, add this:

RegisterFailHandler(aliU.FastFail)

func FileExists added in v0.3.7

func FileExists(filename string) bool

fileExists checks if a file exists and is not a directory

func FiveCharPrefix

func FiveCharPrefix(s string) string

func FliterFloat64Array

func FliterFloat64Array(a []float64, filter func(f float64) bool) []float64

func Folderify

func Folderify(filename string) string

func GzipHandler added in v0.3.3

func GzipHandler(h http.Handler) http.Handler

GzipHandler wraps an HTTP handler, to transparently gzip the response body if the client supports it (via the Accept-Encoding header). This will compress at the default compression level.

func Mapify

func Mapify(thing interface{}) (map[string]interface{}, error)

Mapify converts any struct to a json friendly map of string to interface it expects the thing to have autogenerated json tags float64 are supported while ints are not Damn and embedded strucs are not flattened by default :p

func MaxInt

func MaxInt(a, b int) int

func MaxInt64

func MaxInt64(a, b int64) int64

func MeanFloat64

func MeanFloat64(a []float64) float64

func MeanInt64 added in v0.2.1

func MeanInt64(a []int64) float64

func MedianFloat64

func MedianFloat64(input []float64) (median float64)

func MedianInt64 added in v0.2.1

func MedianInt64(input []int64) (median float64)

it returns the median of a slice of int64 it returns float64 because sometimes the median is not an int

func MergeMaps added in v0.3.5

func MergeMaps[T comparable, U any](a map[T]U, b map[T]U) map[T]U

func MinInt

func MinInt(a, b int) int

func MinInt64

func MinInt64(a, b int64) int64

func MustNewGzipLevelHandler added in v0.3.3

func MustNewGzipLevelHandler(level int) func(http.Handler) http.Handler

MustNewGzipLevelHandler behaves just like NewGzipLevelHandler except that in an error case it panics rather than returning an error.

func NewGzipLevelHandler added in v0.3.3

func NewGzipLevelHandler(level int) (func(http.Handler) http.Handler, error)

NewGzipLevelHandler returns a wrapper function (often known as middleware) which can be used to wrap an HTTP handler to transparently gzip the response body if the client supports it (via the Accept-Encoding header). Responses will be encoded at the given gzip compression level. An error will be returned only if an invalid gzip compression level is given, so if one can ensure the level is valid, the returned error can be safely ignored.

func NextID

func NextID() string

NextID is used to generate sessionid s uses the time reverses it, to avoid problems like "hot hashes" and busy shards an overkill but a good practice

func NextId

func NextId() string

used to generate sessionid s uses the time reverses it, to avoid problems like "hot hashes" and busy shards and over kill but a good practice

func ParseDuration added in v0.2.9

func ParseDuration(durationStr string) (time.Duration, error)

ParseDuration gets a string in the format of 01:03:04 and returns a time.Duration assuming this is hour:minutes:seconds

func PrettyPrint added in v0.3.12

func PrettyPrint[T any](r *T) string

func RandStr100

func RandStr100(length int) string

func RandomString

func RandomString(length int, includeUpperCase bool, includeDigits bool) string

func RunCommand added in v0.3.7

func RunCommand(pwd string, name string, args ...string) (stdout, stderr string, err error)

func SafeMarshal added in v0.2.7

func SafeMarshal(s interface{}) (string, error)

func SafeMarshalBytes added in v0.2.8

func SafeMarshalBytes(s interface{}) ([]byte, error)

func SafeUnmarshal added in v0.2.6

func SafeUnmarshal(encoded string, out interface{}) error

func SafeUnmarshalBytes added in v0.2.8

func SafeUnmarshalBytes(compressedData []byte, out interface{}) error

func Shuffle added in v0.3.10

func Shuffle[K comparable](a []K) []K

func SleepItOff

func SleepItOff(d time.Duration)

func Spinner

func Spinner() string

func StoragePathFromURL

func StoragePathFromURL(url *url.URL) (string, error)

func StringArrayContains

func StringArrayContains(a []string, s string) bool

func StringArraysHaveSameElements

func StringArraysHaveSameElements(a, b []string) bool

func TruncFloat added in v0.3.11

func TruncFloat(f float64, prec int) (float64, error)

from https://stackoverflow.com/a/77009270/487855 prec controls the number of digits (excluding the exponent) prec of -1 uses the smallest number of digits

func UniqueArray

func UniqueArray[K comparable](a []K) []K

func UniqueIDForBlob

func UniqueIDForBlob(blob []byte, PrependFolder bool) string

func Unzipb64

func Unzipb64(s string) (string, error)

func Zipb64

func Zipb64(s string) string

Types

type GzipResponseWriter added in v0.3.3

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

GzipResponseWriter provides an http.ResponseWriter interface, which gzips bytes before writing them to the underlying response. This doesn't close the writers, so don't forget to do that.

func (*GzipResponseWriter) Close added in v0.3.3

func (w *GzipResponseWriter) Close() error

Close will close the gzip.Writer and will put it back in the gzipWriterPool.

func (*GzipResponseWriter) Flush added in v0.3.3

func (w *GzipResponseWriter) Flush()

Flush flushes the underlying *gzip.Writer and then the underlying http.ResponseWriter if it is an http.Flusher. This makes GzipResponseWriter an http.Flusher.

func (*GzipResponseWriter) Write added in v0.3.3

func (w *GzipResponseWriter) Write(b []byte) (int, error)

Write appends data to the gzip writer.

func (*GzipResponseWriter) WriteHeader added in v0.3.3

func (w *GzipResponseWriter) WriteHeader(code int)

WriteHeader will check if the gzip writer needs to be lazily initiated and then pass the code along to the underlying ResponseWriter.

type SortableFloat64Array

type SortableFloat64Array []float64

func (SortableFloat64Array) Len

func (a SortableFloat64Array) Len() int

func (SortableFloat64Array) Less

func (a SortableFloat64Array) Less(i, j int) bool

func (SortableFloat64Array) Swap

func (a SortableFloat64Array) Swap(i, j int)

type SortableInt64Array added in v0.2.1

type SortableInt64Array []int64

func (SortableInt64Array) Len added in v0.2.1

func (a SortableInt64Array) Len() int

func (SortableInt64Array) Less added in v0.2.1

func (a SortableInt64Array) Less(i, j int) bool

func (SortableInt64Array) Swap added in v0.2.1

func (a SortableInt64Array) Swap(i, j int)

type SortableStringArray

type SortableStringArray []string

func (SortableStringArray) Len

func (a SortableStringArray) Len() int

func (SortableStringArray) Less

func (a SortableStringArray) Less(i, j int) bool

func (SortableStringArray) Swap

func (a SortableStringArray) Swap(i, j int)

Jump to

Keyboard shortcuts

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