utils

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2020 License: MIT Imports: 17 Imported by: 46

README

Utils

Release Discord Test Security Linter

A collection of common functions but with better performance, less allocations and no dependencies created for Fiber.

// go test -v -benchmem -run=^$ -bench=Benchmark_ -count=2

Benchmark_GetMIME/fiber               14287550                84.2 ns/op             0 B/op          0 allocs/op
Benchmark_GetMIME/fiber               14819698                78.3 ns/op             0 B/op          0 allocs/op
Benchmark_GetMIME/default              6459128                 184 ns/op             0 B/op          0 allocs/op
Benchmark_GetMIME/default              6385042                 184 ns/op             0 B/op          0 allocs/op

Benchmark_UUID/fiber                  17652744                59.1 ns/op            48 B/op          1 allocs/op
Benchmark_UUID/fiber                  19361145                58.5 ns/op            48 B/op          1 allocs/op
Benchmark_UUID/default                 4271024                 281 ns/op            64 B/op          2 allocs/op
Benchmark_UUID/default                 4435306                 278 ns/op            64 B/op          2 allocs/op

Benchmark_ToLower/fiber               22987184                48.2 ns/op            48 B/op          1 allocs/op
Benchmark_ToLower/fiber               24491794                49.6 ns/op            48 B/op          1 allocs/op
Benchmark_ToLower/default              9232608                 123 ns/op            48 B/op          1 allocs/op
Benchmark_ToLower/default              9454870                 123 ns/op            48 B/op          1 allocs/op

Benchmark_ToLowerBytes/fiber          44463876                26.1 ns/op             0 B/op          0 allocs/op
Benchmark_ToLowerBytes/fiber          39997200                26.1 ns/op             0 B/op          0 allocs/op
Benchmark_ToLowerBytes/default        14879088                77.6 ns/op            48 B/op          1 allocs/op
Benchmark_ToLowerBytes/default        14631433                79.2 ns/op            48 B/op          1 allocs/op

Benchmark_ToUpper/fiber               22648730                49.4 ns/op            48 B/op          1 allocs/op
Benchmark_ToUpper/fiber               23084425                48.6 ns/op            48 B/op          1 allocs/op
Benchmark_ToUpper/default              9520122                 124 ns/op            48 B/op          1 allocs/op
Benchmark_ToUpper/default              9375014                 133 ns/op            48 B/op          1 allocs/op

Benchmark_ToUpperBytes/fiber          44439176                25.6 ns/op             0 B/op          0 allocs/op
Benchmark_ToUpperBytes/fiber          44458934                25.5 ns/op             0 B/op          0 allocs/op
Benchmark_ToUpperBytes/default        15347073                74.1 ns/op            48 B/op          1 allocs/op
Benchmark_ToUpperBytes/default        15511370                74.2 ns/op            48 B/op          1 allocs/op

Benchmark_EqualFolds/fiber            34297864                33.8 ns/op             0 B/op          0 allocs/op
Benchmark_EqualFolds/fiber            34285322                34.0 ns/op             0 B/op          0 allocs/op
Benchmark_EqualFolds/default          12756945                91.8 ns/op             0 B/op          0 allocs/op
Benchmark_EqualFolds/default          13015282                91.1 ns/op             0 B/op          0 allocs/op

Benchmark_Trim/fiber                  207314002               5.85 ns/op             0 B/op          0 allocs/op
Benchmark_Trim/fiber                  207386125               5.78 ns/op             0 B/op          0 allocs/op
Benchmark_Trim/default                16506302                68.5 ns/op            32 B/op          1 allocs/op
Benchmark_Trim/default                16669119                68.9 ns/op            32 B/op          1 allocs/op

Benchmark_TrimLeft/fiber              343254828               3.47 ns/op             0 B/op          0 allocs/op
Benchmark_TrimLeft/fiber              344407171               3.45 ns/op             0 B/op          0 allocs/op
Benchmark_TrimLeft/default            24999790                46.4 ns/op            32 B/op          1 allocs/op
Benchmark_TrimLeft/default            25001926                45.3 ns/op            32 B/op          1 allocs/op

Benchmark_TrimRight/fiber             374543056               3.15 ns/op             0 B/op          0 allocs/op
Benchmark_TrimRight/fiber             336067616               3.15 ns/op             0 B/op          0 allocs/op
Benchmark_TrimRight/default           20868186                52.8 ns/op            32 B/op          1 allocs/op
Benchmark_TrimRight/default           21434695                55.1 ns/op            32 B/op          1 allocs/op

Documentation

Index

Constants

View Source
const MIMEOctetStream = "application/octet-stream"

Variables

This section is empty.

Functions

func AssertEqual

func AssertEqual(t testing.TB, a interface{}, b interface{}, description ...string)

AssertEqual checks if values are equal

func ByteSize added in v0.0.7

func ByteSize(bytes uint64) string

Copyright github.com/cloudfoundry/bytefmt ByteSize returns a human-readable byte string of the form 10M, 12.5K, and so forth. The unit that results in the smallest number greater than or equal to 1 is always chosen.

func EqualsFold

func EqualsFold(b, s []byte) (equals bool)

EqualFold the equivalent of bytes.EqualFold

func FunctionName added in v0.0.6

func FunctionName(fn interface{}) string

Returns function name

func GetArgument

func GetArgument(arg string) bool

GetArgument check if key is in arguments

func GetBytes

func GetBytes(s string) (bs []byte)

#nosec G103 GetBytes returns a byte pointer without allocation

func GetCharPos

func GetCharPos(s string, char byte, matchCount int) int

GetCharPos ...

func GetMIME

func GetMIME(extension string) (mime string)

GetMIME returns the content-type of a file extension

func GetString

func GetString(b []byte) string

#nosec G103 GetString returns a string pointer without allocation

func GetTrimmedParam

func GetTrimmedParam(param string) string

GetTrimmedParam trims the ':' & '?' from a string

func ImmutableString added in v0.0.4

func ImmutableString(s string) string

ImmutableString returns a immutable string with allocation

func MemoryTotal added in v0.0.7

func MemoryTotal() uint64

Returns total memory in bytes

func StatusMessage added in v0.0.2

func StatusMessage(status int) string

StatusMessage returns the correct message for the provided HTTP statuscode

func ToLower

func ToLower(b string) string

ToLower is the equivalent of strings.ToLower

func ToLowerBytes

func ToLowerBytes(b []byte) []byte

ToLowerBytes is the equivalent of bytes.ToLower

func ToUpper

func ToUpper(b string) string

ToUpper is the equivalent of strings.ToUpper

func ToUpperBytes

func ToUpperBytes(b []byte) []byte

ToUpperBytes is the equivalent of bytes.ToUpper

func Trim

func Trim(s string, cutset byte) string

Trim is the equivalent of strings.Trim

func TrimLeft

func TrimLeft(s string, cutset byte) string

TrimLeft is the equivalent of strings.TrimLeft

func TrimRight

func TrimRight(s string, cutset byte) string

TrimRight is the equivalent of strings.TrimRight

func UUID added in v0.0.4

func UUID() string

Types

This section is empty.

Directories

Path Synopsis
Package memory provides a single method reporting total system memory accessible to the kernel.
Package memory provides a single method reporting total system memory accessible to the kernel.

Jump to

Keyboard shortcuts

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