Documentation ¶
Index ¶
- Constants
- func BytesToString(b []byte) string
- func CheckIdentifier(s string, checkLeadChar bool, specialCharStr string) error
- func CheckIdentifierWithDefault(s string) error
- func CheckPasswordStrength(password string, ...) error
- func CheckPasswordStrengthWithDefault(password string) error
- func CombineMessageWithError(message string, err error) string
- func ConvertInterfaceSliceToString(s []interface{}, c string) string
- func ConvertInterfaceToMapInterfaceInterface(in interface{}) (map[interface{}]interface{}, error)
- func ConvertInterfaceToSliceInterface(in interface{}) ([]interface{}, error)
- func ConvertNumberToString(in interface{}) (string, error)
- func ConvertSliceToString[T types.Primitive](s []T, c string) string
- func ConvertToBool(in interface{}) (bool, error)
- func ConvertToFloat(in interface{}) (float64, error)
- func ConvertToInt(in interface{}) (int, error)
- func ConvertToInt64(in interface{}) (int64, error)
- func ConvertToSlice(in interface{}, kind reflect.Kind) (interface{}, error)
- func ConvertToString(in interface{}) (string, error)
- func ConvertToUint(in interface{}) (uint, error)
- func ConvertToUint64(in interface{}) (uint64, error)
- func CopyStructWithFields(in interface{}, fields ...string) (interface{}, error)
- func CopyStructWithoutFields(in interface{}, fields ...string) (interface{}, error)
- func ElementInSlice[T types.Primitive](s []T, e T) bool
- func ElementInSliceInterface(s interface{}, e interface{}) (bool, error)
- func GetParentDir(absPath string) (string, error)
- func GetRandomBytes(s string, num int) []byte
- func GetRandomDigitalString(num int) string
- func GetRandomNormalCharString(num int) string
- func GetRandomSpecialString(num int) string
- func GetRandomString(s string, num int) string
- func GetRandomStringWithDefault() string
- func GetValueOfStruct(in interface{}, field string) (interface{}, error)
- func IntersectSlice[T types.Primitive](first, second []T) []T
- func IsAbs(path string) bool
- func IsAbsUnix(path string) bool
- func IsAbsWindows(path string) bool
- func IsRandomValue(value interface{}) (bool, error)
- func KeyInMap(m interface{}, k interface{}) (bool, error)
- func KeyPathExists(data []byte, keys ...string) bool
- 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 NewMapWithStructTag(m map[string]interface{}, in interface{}, tag string) (map[string]interface{}, error)
- func QuickSort(comparableList []Comparable) error
- func QuickSortAsc(comparableList []Comparable) error
- func QuickSortDesc(comparableList []Comparable) error
- func Retry(doFunc func() error, option *RetryOption) error
- func ReverseString(s string) string
- func SetRandomValueToNil(values ...interface{}) error
- func SetValueOfStruct(in interface{}, field string, value interface{}) error
- func SetValueOfStructByKind(in interface{}, field string, value interface{}, kind reflect.Kind) error
- func SetValueOfStructByTag(in interface{}, field string, value interface{}, tag string) error
- func SetValuesWithMap(in interface{}, fields map[string]interface{}) error
- func SetValuesWithMapAndRandom(in interface{}, fields map[string]interface{}) error
- func SetValuesWithMapAndRandomByTag(in interface{}, fields map[string]interface{}, tag string) error
- func SetValuesWithMapByTag(in interface{}, fields map[string]interface{}, tag string) error
- func StringKeyInMap(m map[string]string, str string) bool
- func StringToBytes(s string) []byte
- func SubtractSlice[T types.Primitive](first, second []T) []T
- func TrimSpaceOfStructString(in interface{}) error
- func UnionSlice[T types.Primitive](first, second []T) []T
- func UnmarshalToMapWithStructTag(data []byte, in interface{}, tag string) (map[string]interface{}, error)
- func UnmarshalToMapWithStructTagFromString(s string, in interface{}, tag string) (map[string]interface{}, error)
- func ValueInMap(m interface{}, v interface{}) (bool, error)
- type Bucket
- type Comparable
- type CompareResult
- type RetryOption
- type Timer
Constants ¶
const ( DefaultLetters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-,.?_" DefaultNormalCharString = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" DefaultUpperCaseCharString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" DefaultLowerCaseCharString = "abcdefghijklmnopqrstuvwxyz" DefaultDigitalCharString = "0123456789" DefaultSpecialCharString = "+-,.?_" DefaultNormalCharNum = 6 DefaultUpperCaseCharNum = 2 DefaultLowerCaseCharNum = 4 DefaultDigitalNum = 3 DefaultSpecialNum = 2 DefaultMinPasswordLength = 8 DefaultMaxPasswordLength = 20 DefaultMinUpperCaseCharNum = 1 DefaultMinLowerCaseCharNum = 1 DefaultMinDigitalCharNum = 1 DefaultMinSpecialCharNum = 1 )
const ( MinMaxRetryCount = -1 MaxMaxRetryCount = constant.MaxInt DefaultMaxRetryCount = 10 DefaultDelayTime = 500 * time.Millisecond DefaultMaxWaitTime = 10 * time.Second )
const (
DefaultIdentifierSpecialCharStr = "_"
)
Variables ¶
This section is empty.
Functions ¶
func BytesToString ¶ added in v0.1.7
BytesToString converts byte slice type to string
func CheckIdentifier ¶ added in v0.3.17
CheckIdentifier checks if the given string is a valid identifier
func CheckIdentifierWithDefault ¶ added in v0.3.17
CheckIdentifierWithDefault checks if the given string is a valid identifier, if not, return the default value
func CheckPasswordStrength ¶ added in v0.3.17
func CheckPasswordStrength(password string, minLen, maxLen, minUpperCaseCharNum, minLowerCaseCharNum, minDigitCharNum, minSpecialCharNum int, supportedSpecialCharString string) error
CheckPasswordStrength checks the strength of password
func CheckPasswordStrengthWithDefault ¶ added in v0.3.17
CheckPasswordStrengthWithDefault checks the strength of password with default parameters
func CombineMessageWithError ¶ added in v0.2.20
CombineMessageWithError returns a new string which combines given message and error
func ConvertInterfaceSliceToString ¶ added in v0.3.18
ConvertInterfaceSliceToString converts the interface slice to string, it uses c as the separation character
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 ConvertSliceToString ¶ added in v0.3.18
ConvertSliceToString converts the slice to string, it uses c as the separation character
func ConvertToBool ¶ added in v0.2.23
func ConvertToFloat ¶ added in v0.2.23
func ConvertToInt ¶ added in v0.2.23
func ConvertToInt64 ¶ added in v0.3.16
func ConvertToSlice ¶ added in v0.2.23
func ConvertToString ¶ added in v0.2.23
func ConvertToUint ¶ added in v0.2.23
func ConvertToUint64 ¶ added in v0.3.16
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
- if fields argument is empty, a new struct which contains the whole fields of input struct will be returned
- technically, for convenience purpose, this function creates a new struct as same as input struct, then removes fields that do 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 6. if fields argument is empty, a new struct which contains the whole fields of input struct will be returned
func ElementInSlice ¶
ElementInSlice checks if given element is in the slice
func ElementInSliceInterface ¶ added in v0.3.18
ElementInSliceInterface checks if given element is in the slice
func GetParentDir ¶ added in v0.3.13
GetParentDir returns the parent directory of the given path, it will not change the separate character
func GetRandomBytes ¶ added in v0.3.17
func GetRandomDigitalString ¶ added in v0.3.17
GetRandomDigitalString returns a random string with given length
func GetRandomNormalCharString ¶ added in v0.3.17
GetRandomNormalCharString returns a random string with given length
func GetRandomSpecialString ¶ added in v0.3.17
GetRandomSpecialString returns a random string with given length
func GetRandomString ¶ added in v0.3.17
GetRandomString returns a random string from given string with given length
func GetRandomStringWithDefault ¶ added in v0.3.17
func GetRandomStringWithDefault() string
GetRandomStringWithDefault returns a random string with default length
func GetValueOfStruct ¶ added in v0.2.10
GetValueOfStruct get value of specified field of input struct, the fields must exist and be exported, otherwise, it will return an error, the first argument must be a pointer to struct
func IntersectSlice ¶ added in v0.3.18
IntersectSlice returns the intersection of two slices
func IsAbs ¶ added in v0.3.12
IsAbs returns if given path is an absolute path, this function is not related to the platform, it works for both unix like and windows paths
func IsAbsUnix ¶ added in v0.3.12
IsAbsUnix returns if given path is an absolute path of unix like system
func IsAbsWindows ¶ added in v0.3.12
IsAbsUnix returns if given path is an absolute path of windows system
func IsRandomValue ¶ added in v0.2.31
IsRandomValue checks if given value is a random value
func KeyPathExists ¶ added in v0.3.18
KeyPathExists checks if the key path exists in the json data
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
MarshalStructWithoutFields marshals input struct using json.Marshal() without given fields, first argument must be a pointer to struct, not the struct itself
func NewMapWithStructTag ¶ added in v0.2.17
func NewMapWithStructTag(m map[string]interface{}, in interface{}, tag string) (map[string]interface{}, error)
NewMapWithStructTag returns a new map as the result, it loops the keys of given map and tags of the struct, if key and tag are same, the field of the input struct will be the key of the new map, the value of the given map will be the value of the new map
func QuickSort ¶ added in v0.3.18
func QuickSort(comparableList []Comparable) error
func QuickSortAsc ¶ added in v0.3.18
func QuickSortAsc(comparableList []Comparable) error
func QuickSortDesc ¶ added in v0.3.18
func QuickSortDesc(comparableList []Comparable) error
func Retry ¶ added in v0.1.4
func Retry(doFunc func() error, option *RetryOption) error
Retry retries the function until it returns no error or reaches max retry count or max wait time, either one is earlier, if option is nil, it will only call the function once, and no retry.
func ReverseString ¶ added in v0.3.18
ReverseString reverses a string
func SetRandomValueToNil ¶ added in v0.2.25
func SetRandomValueToNil(values ...interface{}) error
SetRandomValueToNil set each value in slice values if value is a random value
func SetValueOfStruct ¶ added in v0.2.3
SetValueOfStruct sets value of specified field of input struct, the fields must exist and be exported, otherwise, it will return an error, the first argument must be a pointer to struct if value is nil, the field value will be set to ZERO value of the type
func SetValueOfStructByKind ¶ added in v0.2.23
func SetValueOfStructByTag ¶ added in v0.3.16
SetValueOfStructByTag sets value of specified field of input struct, field in this function represents the tag of the struct field, the concerning struct field must exist and be exported, otherwise, it will return an error, the first argument must be a pointer to struct if value is nil, the field value will be set to ZERO value of the type
func SetValuesWithMap ¶ added in v0.2.26
SetValuesWithMap sets values of input struct with given map, the fields of map must exist and be exported, otherwise, it will return an error, the first argument must be a pointer to struct
func SetValuesWithMapAndRandom ¶ added in v0.2.27
SetValuesWithMapAndRandom sets values of input struct with given map, if fields in struct does not exist in given map, some of them--depends on the data type--will be set with default value, the fields of map must exist and be exported, otherwise, it will return an error, the first argument must be a pointer to struct
func SetValuesWithMapAndRandomByTag ¶ added in v0.3.16
func SetValuesWithMapAndRandomByTag(in interface{}, fields map[string]interface{}, tag string) error
SetValuesWithMapAndRandomByTag sets values of input struct with given map, field in this function represents the tag of the struct field, if fields in struct does not exist in given map, some of them--depends on the data type--will be set with default value, the fields of map must exist and be exported, otherwise, it will return an error, the first argument must be a pointer to struct
func SetValuesWithMapByTag ¶ added in v0.3.16
SetValuesWithMapByTag sets values of input struct with given map, the fields of map represents the tag of the struct field, the concerning struct field must exist and be exported, otherwise, it will return an error, the first argument must be a pointer to struct
func StringKeyInMap ¶ added in v0.3.3
StringKeyInMap checks if a string key is in the map
func StringToBytes ¶ added in v0.1.7
StringToBytes converts string type to byte slice
func SubtractSlice ¶ added in v0.3.18
SubtractSlice returns all the elements in first but not in second
func TrimSpaceOfStructString ¶
func TrimSpaceOfStructString(in interface{}) error
TrimSpaceOfStructString trims spaces of each member variable of the struct
func UnionSlice ¶ added in v0.3.18
UnionSlice returns the union of two slices
func UnmarshalToMapWithStructTag ¶ added in v0.2.18
func UnmarshalToMapWithStructTag(data []byte, in interface{}, tag string) (map[string]interface{}, error)
UnmarshalToMapWithStructTag returns a map as the result, it works as following logic: 1. unmarshals given data to a temporary map to get keys 2. unmarshals given data to the input struct, to get field names and values with appropriate data types 3. loop keys in the temporary map, loops tags of the input struct in a nested loop 4. if the key matches the tag, set field name as the key of result map, set field value as the value of the result map
func UnmarshalToMapWithStructTagFromString ¶ added in v0.2.18
func UnmarshalToMapWithStructTagFromString(s string, in interface{}, tag string) (map[string]interface{}, error)
UnmarshalToMapWithStructTagFromString converts given string to []byte and then call UnmarshalToMapWithStructTag() function
func ValueInMap ¶
ValueInMap checks if given value is in the map
Types ¶
type Bucket ¶ added in v0.3.17
type Bucket struct {
// contains filtered or unexported fields
}
func (*Bucket) Get ¶ added in v0.3.17
Get gets a token from bucket, if bucket is empty, it will return error immediately
func (*Bucket) GetForever ¶ added in v0.3.17
func (b *Bucket) GetForever()
GetForever gets a token from bucket, if bucket is empty, it will wait forever until it gets a token successfully
func (*Bucket) GetWithTimeout ¶ added in v0.3.17
GetWithTimeout gets a token from bucket, if bucket is empty, it will return error after timeout note that each time it failed to get the token, it will sleep for 10ms, so beware of the interval value when initializing the bucket
type Comparable ¶ added in v0.3.18
type Comparable interface {
Compare(other Comparable) (CompareResult, error)
}
type CompareResult ¶ added in v0.3.18
type CompareResult int
const ( CompareResultUnknown CompareResult = iota CompareResultEqual CompareResultGT CompareResultLT )
type RetryOption ¶ added in v0.1.4
type RetryOption struct { MaxRetryCount int MaxWaitTime time.Duration DelayTime time.Duration Logger *log.Logger }
RetryOption is options for Retry()
func NewRetryOption ¶ added in v0.1.4
func NewRetryOption(maxRetryCount int, maxWaitTime, delayTime time.Duration, logger *log.Logger) *RetryOption
NewRetryOption returns RetryOption
func NewRetryOptionWithDefault ¶ added in v0.3.18
func NewRetryOptionWithDefault() *RetryOption
NewRetryOptionWithDefault returns RetryOption with default values
func NewRetryOptionWithLogger ¶ added in v0.3.18
func NewRetryOptionWithLogger(logger *log.Logger) *RetryOption
NewRetryOptionWithLogger returns RetryOption with given logger
func (*RetryOption) Validate ¶ added in v0.3.18
func (ro *RetryOption) Validate() error
Validate validates RetryOption
type Timer ¶ added in v0.3.16
type Timer struct {
// contains filtered or unexported fields
}
func NewTimerWithDefault ¶ added in v0.3.16
func NewTimerWithDefault() *Timer
NewTimerWithDefault returns a new *Timer
func (*Timer) GetNextStartTime ¶ added in v0.3.16
GetNextStartTime returns the next start time