gocandy

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2021 License: MIT Imports: 17 Imported by: 0

README

gocandy

The Go candies

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AESDecrypt added in v1.3.0

func AESDecrypt(message string, key string) (decrypted string, err error)

AESDecrypt decrypts the message using the given key. Only accept messages conforming to what returned by AESEncrypt().

func AESEncrypt added in v1.3.0

func AESEncrypt(message string, key string) (encrypted string, err error)

AESEncrypt encrypts the message using the given key. the key is md5 hashed to support any length. Result is base64 encoded to support transporting in multiple format.

func AssertEqual

func AssertEqual(a interface{}, b interface{}) error

AssertEqual returns error if a != b

func AssertInequal

func AssertInequal(a interface{}, b interface{}) error

AssertInequal returns error if a != b

func BeheadStrings

func BeheadStrings(sarr []string) (string, []string)

BeheadStrings splits the first element in the array and rest of them

func JSONForHTTPRequest

func JSONForHTTPRequest(object interface{}) *bytes.Reader

JSONForHTTPRequest is the fast path to create reader to send on unmarshal failure, return empty json object.

func MakeError added in v1.2.0

func MakeError(contents ...interface{}) error

func MkTemp

func MkTemp() string

MkTemp generates temporary filename depends on current time and added some randomization..

func RandString

func RandString(randopt string, length int) string

RandString returns a random string with given length

func ReadAllClose

func ReadAllClose(clsr io.ReadCloser) ([]byte, error)

ReadAllClose works like ioutil.ReadAll, but will close the object.

func ReadSufficient

func ReadSufficient(rd io.Reader, buffer []byte, expectLen uint64) (uint64, error)

ReadSufficient retry until sufficient bytes are read from reader, or fail with error reported.

func WrapError added in v1.2.0

func WrapError(e error, contents ...interface{}) error

func WriteArbitraryStringToFile

func WriteArbitraryStringToFile(filename string, content string, flag int) error

WriteArbitraryStringToFile do as it says. saves your time.

func WriteSufficient

func WriteSufficient(wr io.Writer, buffer []byte, expectLen uint64) (uint64, error)

WriteSufficient retry until sufficient bytes are written to writer, or fail on error.

Types

type ByteBuffer added in v1.1.0

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

func NewByteBuffer added in v1.1.0

func NewByteBuffer(buf []byte) *ByteBuffer

func (*ByteBuffer) Make added in v1.1.0

func (buf *ByteBuffer) Make() []byte

func (*ByteBuffer) Progress added in v1.1.0

func (buf *ByteBuffer) Progress(prog int) *ByteBuffer

type LockedList

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

LockedList is a linked list with mutex. Front() and Back() is not provided, since accessing them in concurrent environment is never safe. Size() is provided but strongly against using it. it is very useful when you need thread safe log accumulators. performance problem exists.

func NewLockedList

func NewLockedList() *LockedList

NewLockedList create a lockedlist

func (*LockedList) PopBack

func (ll *LockedList) PopBack() interface{}

PopBack explains itself.

func (*LockedList) PopFront

func (ll *LockedList) PopFront() interface{}

PopFront explains itself.

func (*LockedList) PushBack

func (ll *LockedList) PushBack(elem interface{})

PushBack explains itself.

func (*LockedList) PushFront

func (ll *LockedList) PushFront(elem interface{})

PushFront explains itself.

func (*LockedList) Size

func (ll *LockedList) Size() int

Size return the size of the list.

type WaitOnce

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

WaitOnce executes exactly once. When the function is called and not returned, other calls to this will be blocked.

func NewWaitOnce

func NewWaitOnce() *WaitOnce

NewWaitOnce creates a WaitOnce Object that can share

func (*WaitOnce) Do

func (w *WaitOnce) Do(fn func(interface{}), args interface{})

Do executes the given function exactly once.

type WrappedError added in v1.2.0

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

func (WrappedError) Error added in v1.2.0

func (we WrappedError) Error() string

func (WrappedError) Unwrap added in v1.2.0

func (we WrappedError) Unwrap() error

Jump to

Keyboard shortcuts

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