utils

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentEncodingHeader = "Content-Encoding"
	ContentEncodingGZIP   = "gzip"
)
View Source
const (
	DefaultIPv4 = "0.0.0.0"
	DefaultIPv6 = "0000:0000:0000:0000:0000:0000:0000:0000"
)

Variables

View Source
var (
	ErrLengthsDontMatch = errors.New("lengths don't match")
	ErrTypesDontMatch   = errors.New("types don't match")
	ErrKeysDontMatch    = errors.New("keys don't match")
	ErrValuesDontMatch  = errors.New("values don't match")
)

Functions

func AreSlicesIntersect

func AreSlicesIntersect[T comparable](slice1, slice2 []T) bool

func CloneRequestBody

func CloneRequestBody(r *http.Request) (body string)

func CloneResponseBody

func CloneResponseBody(r *http.Response) (body string)

func CloserFunc

func CloserFunc(r io.Reader, close func() error) io.ReadCloser

func DurationUntilNextInterval

func DurationUntilNextInterval(now time.Time, interval time.Duration) time.Duration

func EscapeChars

func EscapeChars(str string, chars map[rune]struct{}) string

func FillEmptyIP

func FillEmptyIP(ipv4, ipv6 string) (string, string)

func FuncName

func FuncName() string

func GetFirst

func GetFirst(str string) string

func GetRequestIP

func GetRequestIP(r *http.Request) (requestIP string)

func GetSecond

func GetSecond(str string) string

func IsInSlice

func IsInSlice[T comparable](i T, slice []T) bool

func JoinIPVersions

func JoinIPVersions(ipv4, ipv6 string) (ip string)

func JoinParams

func JoinParams(first, second string) string

func JoinQuoted

func JoinQuoted(lines []string, quote, separator string) string

func JoinQuotedInt

func JoinQuotedInt(lines []int, quote, separator string) string

func Retry

func Retry(f func() error, times int)

func RetryOverTime

func RetryOverTime(f func() error, timeout time.Duration, tick time.Duration) error

func SQLReplaceArgs

func SQLReplaceArgs(query string, args ...any) string

func SetCORS

func SetCORS(w http.ResponseWriter)

func SetContentTypeHeader

func SetContentTypeHeader(w http.ResponseWriter, contentType ContentType)

func SetCorsHeader

func SetCorsHeader(w http.ResponseWriter)

func SplitIPVersions

func SplitIPVersions(ip string) (ipv4, ipv6 string)

func ToUnderscoreACII

func ToUnderscoreACII(s string) (underscored string)

func UnGzipBody

func UnGzipBody(bodyContent []byte) ([]byte, error)

Types

type Commission

type Commission Percent

func (Commission) AddTo

func (e Commission) AddTo(value float64) float64

func (Commission) SubtractFrom

func (e Commission) SubtractFrom(value float64) float64

type ContentType

type ContentType string
const (
	ContentTypeApplicationJSON ContentType = "application/json"
	ContentTypeTextHTML        ContentType = "text/html"
)

type Diff

type Diff struct {
	Path  string
	Left  string
	Right string
	Error error
}

type Diffs

type Diffs []Diff

func CompareJSON

func CompareJSON(leftJSON, rightJSON string) (diff Diffs, err error)

func (Diffs) String

func (ds Diffs) String() string

type Distribution

type Distribution []float64

func (*Distribution) GetMax

func (d *Distribution) GetMax() float64

func (*Distribution) GetMin

func (d *Distribution) GetMin() float64

func (*Distribution) GetQuantileValue

func (d *Distribution) GetQuantileValue(quantileNumber uint) float64

func (*Distribution) TrimMax

func (d *Distribution) TrimMax(difference float64)

TrimMax sorts and trims max values if difference is too big, difference 0.25 means 25% between max values

type Percent

type Percent float64
const (
	OnePercent Percent = 0.01
)

func PercentFrom

func PercentFrom[percentT int | int32 | int64 | float32 | float64](percent percentT) Percent

func (Percent) Float64

func (p Percent) Float64() float64

func (*Percent) MarshalJSON

func (p *Percent) MarshalJSON() ([]byte, error)

func (Percent) Scale

func (p Percent) Scale(val float64) float64

Scale returns p% imply that val is 100%

func (Percent) ScaleReversed

func (p Percent) ScaleReversed(val float64) float64

ScaleReversed returns 100% imply that val is p%

func (Percent) String

func (p Percent) String() string

func (*Percent) UnmarshalJSON

func (p *Percent) UnmarshalJSON(data []byte) error

type SQLStringValue

type SQLStringValue string

func ToSQLStringValue

func ToSQLStringValue(lines ...string) []SQLStringValue

type Set

type Set[data comparable] map[data]struct{}

func NewSet

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

func (Set[dataType]) Add

func (s Set[dataType]) Add(data ...dataType)

func (Set[dataType]) Delete

func (s Set[dataType]) Delete(data dataType)

func (Set[dataType]) Exists

func (s Set[dataType]) Exists(data dataType) bool

func (Set[dataType]) Values

func (s Set[dataType]) Values() []dataType

Jump to

Keyboard shortcuts

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