utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConstantTimeStringEquals

func ConstantTimeStringEquals(x, y string) bool

Returns true iff the two string, x and y, have equal contents. Time depends on the length of the string. If length are different, then returns immediately.

func DropRunes

func DropRunes(s string, n int) string

func GenSecureRandomId

func GenSecureRandomId(n int) string

func IsAsciiWord

func IsAsciiWord(s string) bool

func IsAsciiWordWithDigits

func IsAsciiWordWithDigits(s string) bool

func MaskAll

func MaskAll(s string) string

func Masked

func Masked(k string, v string) zap.Field

func RemoveStrFromSliceInPlace

func RemoveStrFromSliceInPlace(slice []string, target string) []string

Remove occupancies of the given string from the slice. Mutates original array.

func TakeRunes

func TakeRunes(s string, n int) string

func TrimAllInPlace

func TrimAllInPlace(slice []string) []string

Trim slice

Types

type ConstError

type ConstError string

func (ConstError) Error

func (e ConstError) Error() string

type SizedBufferPool

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

SizedBufferPool implements a pool of bytes.Buffers in the form of a bounded channel. Buffers are pre-allocated to the requested size.

func NewSizedBufferPool

func NewSizedBufferPool(size int, alloc int) (bp *SizedBufferPool)

SizedBufferPool creates a new BufferPool bounded to the given size. size defines the number of buffers to be retained in the pool and alloc sets the initial capacity of new buffers to minimize calls to make().

The value of alloc should seek to provide a buffer that is representative of most data written to the the buffer (i.e. 95th percentile) without being overly large (which will increase static memory consumption). You may wish to track the capacity of your last N buffers (i.e. using an []int) prior to returning them to the pool as input into calculating a suitable alloc value.

func (*SizedBufferPool) WithBuffer

func (bp *SizedBufferPool) WithBuffer(f func(b *bytes.Buffer))

Run the given function providing a buffer from the pool. The buffer will be returned to the pool when function f has finished its job.

Jump to

Keyboard shortcuts

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