util

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2020 License: BSD-3-Clause Imports: 3 Imported by: 1

README

util

Just some utility functions I really like.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChunkJoinStrings

func ChunkJoinStrings(params []string, maxlength int, sep string) []string

ChunkJoinStrings takes a list of individual parameters and joins them to strings separated by sep, limited by the maxlength. For each item, if appending the item would breach the maxlength, it instead starts to build a new string. Once all of the strings are built, it returns the list of strings.

Types

type BufferPool

type BufferPool struct {
	Buffers chan *bytes.Buffer
}

BufferPool holds the Buffers in a Channel as a queue.

func NewBufferPool

func NewBufferPool(max int) *BufferPool

NewBufferPool creates a new object pool of bytes.Buffer.

func (*BufferPool) New

func (pool *BufferPool) New() (buf *bytes.Buffer)

New takes a Buffer from the pool.

func (*BufferPool) Recycle

func (pool *BufferPool) Recycle(buf *bytes.Buffer)

Recycle returns a BUffer to the pool.

func (*BufferPool) Warmup

func (pool *BufferPool) Warmup(num, length int)

Warmup fills the BufferPool with the specified number of objects up to one below the maximum capacity of the internal channel

type ConcurrentMapString

type ConcurrentMapString struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ConcurrentMapString is a simple map[string]string wrapped with a concurrent-safe API

func NewConcurrentMapString

func NewConcurrentMapString() *ConcurrentMapString

NewConcurrentMapString initializes and returns a pointer to a new ConcurrentMapString instance.

func (*ConcurrentMapString) Add

func (m *ConcurrentMapString) Add(key string, value string) error

Add is used to add a key/value to the map. Returns an error if the key already exists.

func (*ConcurrentMapString) Del

func (m *ConcurrentMapString) Del(key string) error

Del is used to remove a key/value from the map. Returns an error if the key does not exist.

func (*ConcurrentMapString) Exists

func (m *ConcurrentMapString) Exists(key string) bool

Exists is used by external callers to check if a value exists in the map and returns a boolean with the result.

func (*ConcurrentMapString) ForEach

func (m *ConcurrentMapString) ForEach(do func(string, string))

ForEach will call the provided function for each entry in the ConcurrentMapString

func (*ConcurrentMapString) Get

func (m *ConcurrentMapString) Get(key string) (string, error)

Get is used to get a key/value from the map. Returns an error if the key does not exist.

func (*ConcurrentMapString) Length

func (m *ConcurrentMapString) Length() int

Length returns the length of the underlying map.

func (*ConcurrentMapString) Set

func (m *ConcurrentMapString) Set(key string, value string) error

Set is used to change an existing key/value in the map. Returns an error if the key does not exist.

Jump to

Keyboard shortcuts

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