Documentation ¶
Index ¶
- Constants
- func AnyErr(errors ...error) error
- func AnyNil(val ...interface{}) bool
- func AnyString(values ...string) string
- func CauseErr(err error) error
- func Contains(haystack []string, needle string) bool
- func ExtendMap(dest, src map[string]interface{}, overwrite bool)
- func ExtendStrMap(dest, src map[string]string, overwrite bool)
- func FileExists(f string) bool
- func FormatDateStuckTogether(t time.Time) string
- func IP(r *http.Request) string
- func IndirectType(val interface{}) (reflect.Type, error)
- func IndirectValue(value interface{}) interface{}
- func InterfaceDefault(val, def interface{}) interface{}
- func InterfaceToSlice(slice interface{}) []interface{}
- func Intersect(s1 []string, s2 []string) []string
- func IsNil(val interface{}) (result bool)
- func KeyValuesToMap(keyValues ...interface{}) (map[string]interface{}, error)
- func MapToKeyValue(m map[string]interface{}) []interface{}
- func MapToStruct(m map[string]interface{}, s interface{}) error
- func Marshal(in interface{}) ([]byte, error)
- func Max(vars ...int) int
- func Max64(vars ...int64) int64
- func MaxDuration(vars ...time.Duration) time.Duration
- func Min(vars ...int) int
- func Min64(vars ...int64) int64
- func MinDuration(vars ...time.Duration) time.Duration
- func Must(val interface{}, err error) interface{}
- func MustValuePtr(v interface{}) interface{}
- func NewBool(b bool) *bool
- func NewInt(i int) *int
- func NewInt32(i int32) *int32
- func NewInt64(i int64) *int64
- func NewString(s string) *string
- func NewTime(t time.Time) *time.Time
- func PanicErr(err error)
- func PanicNil(val interface{}, err error)
- func ParseInt(val string, def int) int
- func ParsePrivateKey(pemBytes []byte, keyFormat KeyFormat) (key interface{}, err error)
- func ParsePublicKey(pemBytes []byte, keyFormat KeyFormat) (key interface{}, err error)
- func ParseRSAPrivateKey(pemBytes []byte, keyFormat KeyFormat) (*rsa.PrivateKey, error)
- func ParseRSAPublicKey(pemBytes []byte, format KeyFormat) (*rsa.PublicKey, error)
- func ParseUint64(val string, def uint64) uint64
- func Percent(total int64, percent float64) float64
- func PercentFloat(total float64, percent float64) float64
- func PercentInt(total int64, percent int) float64
- func PercentOf(total int64, part int64) float64
- func RandNumber(min, max int64) int64
- func RandString(n int) string
- func RandStringWithType(size int, t RandType) string
- func RandWithDate(t time.Time, size int) string
- func ReadAll(filePath string) ([]byte, error)
- func RemoveFromStrings(values []string, removal ...string) []string
- func RenderText(text string, data interface{}) (string, error)
- func ReplaceAt(str string, replace string, begin int, end int) string
- func ReplaceRune(str string, new rune, index int) string
- func SourcePath() string
- func StringDefault(val, def string) string
- func StructTags(val interface{}) ([]reflect.StructTag, error)
- func StructToMap(input interface{}) map[string]interface{}
- func Sub(s1 []string, s2 []string) []string
- func ToSnakeCase(str string) string
- func UUID() string
- func UniqueStrings(values []string) []string
- func Unmarshal(in []byte, out interface{}) error
- func UnmarshalStruct(from, to interface{}) error
- func ValuePtr(v interface{}) (interface{}, error)
- func Wait(callback func(s os.Signal) error, signals ...os.Signal) (err error)
- func WaitForSignals(signals ...os.Signal)
- type Bits
- type KeyFormat
- type MapPathExtractor
- type RandType
Constants ¶
const ( KeyFormatPKCS1 = 1 KeyFormatPKCS8 = 2 KeyFormatPKIX = 3 )
Variables ¶
This section is empty.
Functions ¶
func AnyNil ¶
func AnyNil(val ...interface{}) bool
AnyNil check if any value of provided values is nil, returns true, otherwise returns false.
func ExtendStrMap ¶
ExtendMap extend dest map by src map. overwrite argument set overwrite policy.
func FileExists ¶
FileExists checks if a file exists and is not a directory before we try using it to prevent further errors.
func FormatDateStuckTogether ¶
func IP ¶
GetIP gets the provided requests IP address by reading off the forwarded-for header (for proxies) and falls back to use the remote address.
func IndirectType ¶
IndirectType returns indirect value's reflection type.
func IndirectValue ¶
func IndirectValue(value interface{}) interface{}
Indirect returns the value that the given interface or pointer references to. A boolean value is also returned to indicate if the value is nil or not (only applicable to interface, pointer, map, and slice). If the value is neither an interface nor a pointer, it will be returned back. reference: https://github.com/go-ozzo/ozzo-validation/blob/master/util.go
func InterfaceDefault ¶
func InterfaceDefault(val, def interface{}) interface{}
InterfaceDefault returns value if it's not nil, otherwise returns the default value.
func InterfaceToSlice ¶
func InterfaceToSlice(slice interface{}) []interface{}
InterfaceToSlice converts interface to slices. If provided value is not list, it will panic.
func Intersect ¶
Intersect returns intersect of two slices. e.g., intersect of [1,2,3] & [2,3,4] = [2,3]
func IsNil ¶
func IsNil(val interface{}) (result bool)
IsNil function check value is nil or no. To check real value of interface is nil or not, should using reflection, check this https://play.golang.org/p/Isoo0CcAvr. Firstly check `val==nil` because reflection can not get value of zero val.
func KeyValuesToMap ¶
KeyValuesToMap convert each pair of slice to a key/value of map.
func MapToKeyValue ¶
func MapToKeyValue(m map[string]interface{}) []interface{}
MapToKeyValue convert map to slice that contain map key and value pairs.
func MapToStruct ¶
MapToStruct convert map to struct by json marshal and Unmarshal
func Must ¶
func Must(val interface{}, err error) interface{}
Must check if error is not nil, so panic, otherwise return value.
func MustValuePtr ¶
func MustValuePtr(v interface{}) interface{}
MustValuePtr returns pointer to the provided value and panic if occurred error.
func PanicNil ¶
func PanicNil(val interface{}, err error)
PanicNil will panic error param if value is nil.
func ParseInt ¶
ParseInt parse integer and returns value if string value is a valid integer or default value
func ParsePrivateKey ¶
func ParsePublicKey ¶
func ParseRSAPrivateKey ¶
func ParseRSAPrivateKey(pemBytes []byte, keyFormat KeyFormat) (*rsa.PrivateKey, error)
ParsePrivateKeyFromPem parses private key from the pem value.
func ParseRSAPublicKey ¶
func ParseUint64 ¶
ParseUint64 parse unsigned integer and returns it if the value is valid, otherwise returns the default value.
func PercentFloat ¶
func PercentInt ¶
func RandNumber ¶
RandNumber generate secure random number in range of [min,max).
func RandStringWithType ¶
func RemoveFromStrings ¶
func RenderText ¶
RenderText parses the provided text and then execute it.
func ReplaceAt ¶
ReplaceAt replace provided string in specific index to another index. removal part is [begin,end). e.g., to replace char "a" in the "salam" word, call ReplaceAt("salam","b",1,2) // result will be "sblam".
func ReplaceRune ¶
ReplaceRune replace single rune in specific index
func SourcePath ¶
func SourcePath() string
SourcePath returns the directory containing the source code that is calling this function.
func StringDefault ¶
StringDefault return default value if provided value is empty.
func StructTags ¶
StructTags return struct all fields tags.
func StructToMap ¶
func StructToMap(input interface{}) map[string]interface{}
StructToMap convert the struct to a map by marshall and un-marshall
func ToSnakeCase ¶
ToSnakeCase returns snake_case of the provided value.
func UniqueStrings ¶
func UnmarshalStruct ¶
func UnmarshalStruct(from, to interface{}) error
UnmarshalStruct marshal provided input to json and then unmarshal json bytes to provided output. input and output can be regular struct, map or struct of protobuf message type.
func ValuePtr ¶
func ValuePtr(v interface{}) (interface{}, error)
ValuePtr returns pointer to the provided value. Provided value can be either by reference or by value.
func Wait ¶
Wait waits until get one signal of your specified signals, then calls to the callback and return result of callback as result of the Wait function.
func WaitForSignals ¶
WaitForSignals simply wait until get a signal which match with your provided signals.
Types ¶
type MapPathExtractor ¶
type MapPathExtractor struct { // Depth is depth of the keys. set to 1 to get just first level of keys. Depth int // Separator defines separator string between keys on each depth. // e.g if we set "." separator set to "." so we will have a.b for // {a:{b:"hello"}} map. Separator string }
MapPathExtractor extract the map paths recursively.
func (MapPathExtractor) Extract ¶
func (e MapPathExtractor) Extract(m map[string]interface{}) []string