common

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2020 License: Apache-2.0 Imports: 7 Imported by: 15

Documentation

Index

Constants

View Source
const (
	DefaultAttempts int64 = 10
	DefaultDelay          = 500 * time.Millisecond
	DefaultTimeout        = 10 * time.Second
)

Variables

This section is empty.

Functions

func BytesToString added in v0.1.7

func BytesToString(b []byte) string

BytesToString converts byte slice type to string

func ConvertInterfaceToMapInterfaceInterface

func ConvertInterfaceToMapInterfaceInterface(in interface{}) (map[interface{}]interface{}, error)

ConvertInterfaceToMapInterfaceInterface converts input data which must be map type to map interface interface, it means each pair of key and value in the map will be interface type

func ConvertInterfaceToSliceInterface

func ConvertInterfaceToSliceInterface(in interface{}) ([]interface{}, error)

ConvertInterfaceToSliceInterface converts input data which must be slice type to interface slice, it means each element in the slice is interface type.

func ConvertNumberToString added in v0.1.7

func ConvertNumberToString(in interface{}) (string, error)

ConvertNumberToString tries to convert number to string, if input is neither number type nor string, it will return error

func ElementInSlice

func ElementInSlice(e interface{}, s interface{}) (bool, error)

ElementInSlice checks if given element is in the slice

func KeyInMap

func KeyInMap(k interface{}, m interface{}) (bool, error)

KeyInMap checks if given key is in the map

func Retry added in v0.1.4

func Retry(doFunc func() error, attempts int64, delay, timeout time.Duration) error

RetryWithRetryOption retries the func until it returns no error or reaches attempts limit or timed out, either one is earlier

func RetryWithRetryOption added in v0.1.4

func RetryWithRetryOption(doFunc func() error, opts ...RetryOption) (err error)

RetryWithRetryOption retries the func until it returns no error or reaches attempts limit or timed out, either one is earlier

func StringToBytes added in v0.1.7

func StringToBytes(s string) []byte

StringToBytes converts string type to byte slice

func TrimSpaceOfStructString

func TrimSpaceOfStructString(in interface{}) error

TrimSpaceOfStructString trims spaces of each member variable of the struct

func ValueInMap

func ValueInMap(v interface{}, m interface{}) (bool, error)

ValueInMap checks if given value is in the map

Types

type RetryOption added in v0.1.4

type RetryOption struct {
	Attempts int64
	Delay    time.Duration
	Timeout  time.Duration
}

RetryOption is options for Retry()

func NewRetryOption added in v0.1.4

func NewRetryOption(attempts int64, delay, timeout time.Duration) RetryOption

NewRetryOption returns RetryOption

Jump to

Keyboard shortcuts

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