Documentation ¶
Index ¶
- Constants
- func BytesToString(b []byte) string
- func ConvertInterfaceToMapInterfaceInterface(in interface{}) (map[interface{}]interface{}, error)
- func ConvertInterfaceToSliceInterface(in interface{}) ([]interface{}, error)
- func ConvertNumberToString(in interface{}) (string, error)
- func CopyStructWithFields(in interface{}, fields ...string) (interface{}, error)
- func CopyStructWithoutFields(in interface{}, fields ...string) (interface{}, error)
- func ElementInSlice(e interface{}, s interface{}) (bool, error)
- func GetValueOfStruct(in interface{}, field string) (interface{}, error)
- func KeyInMap(k interface{}, m interface{}) (bool, error)
- func MarshalStructWithFields(in interface{}, fields ...string) ([]byte, error)
- func MarshalStructWithTag(in interface{}, tag string) ([]byte, error)
- func MarshalStructWithoutFields(in interface{}, fields ...string) ([]byte, error)
- func Retry(doFunc func() error, attempts int64, delay, timeout time.Duration) error
- func RetryWithRetryOption(doFunc func() error, opts ...RetryOption) (err error)
- func SetValueOfStruct(in interface{}, field string, value interface{}) error
- func StringToBytes(s string) []byte
- func TrimSpaceOfStructString(in interface{}) error
- func ValueInMap(v interface{}, m interface{}) (bool, error)
- type RetryOption
Constants ¶
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
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
ConvertNumberToString tries to convert number to string, if input is neither number type nor string, it will return error
func CopyStructWithFields ¶ added in v0.2.3
CopyStructWithFields returns a new struct with only specified fields NOTE:
- tags and values of fields are exactly same
- only exported and addressable fields will be copied
- if any field in fields does not exist in the input struct, it returns error
- if values in input struct is a pointer, then value in the new struct will point to the same object
- returning struct is totally a new data type, so you could not use any (*type) assertion
- technically, for convenience purpose, this function creates a new struct as same as input struct, then removes fields that does not exist in the given fields
func CopyStructWithoutFields ¶ added in v0.2.3
CopyStructWithoutFields returns a new struct without specified fields, there are something you should know. NOTE: 1. tags and values of remaining fields are exactly same 2. only exported and addressable fields will be copied 3. if any field in fields does not exist in the input struct, it simply ignores 4. if values in input struct is a pointer, then value in the new struct will point to the same object 5. returning struct is totally a new data type, so you could not use any (*type) assertion
func ElementInSlice ¶
ElementInSlice checks if given element is in the slice
func GetValueOfStruct ¶ added in v0.2.10
GetValueOfStruct get value of specified field of input struct, the field must exist and be exported, otherwise, it will return an error, the first argument must be a pointer to struct
func MarshalStructWithFields ¶ added in v0.2.3
MarshalStructWithFields marshals input struct using json.Marshal() with given fields, first argument must be a pointer to struct, not the struct itself
func MarshalStructWithTag ¶ added in v0.2.15
MarshalStructWithTag marshals input struct using json.Marshal() with fields that contain given tag, first argument must be a pointer to struct, not the struct itself
func MarshalStructWithoutFields ¶ added in v0.2.3
MarshalStructWithFields marshals input struct using json.Marshal() without given fields, first argument must be a pointer to struct, not the struct itself
func Retry ¶ added in v0.1.4
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 SetValueOfStruct ¶ added in v0.2.3
SetValueOfStruct set value of specified field of input struct, the field must exist and be exported, otherwise, it will return an error, the first argument must be a pointer to struct
func StringToBytes ¶ added in v0.1.7
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 ¶
ValueInMap checks if given value is in the map
Types ¶
type RetryOption ¶ added in v0.1.4
RetryOption is options for Retry()
func NewRetryOption ¶ added in v0.1.4
func NewRetryOption(attempts int64, delay, timeout time.Duration) RetryOption
NewRetryOption returns RetryOption