Documentation ¶
Overview ¶
Package primitives is collection of utility functions to ease working with primitive types in go ─── ACKNOWLEDGEMENTS ─────────────────────────────────────────────────────────── github.com/hoempf/creader github.com/danilopolani/gosc github.com/mina86/unsafeConvert github.com/fmstephe/unsafeutil github.com/alecthomas/unsafeslice ────────────────────────────────────────────────────────────────────────────────
Index ¶
- Constants
- Variables
- func AllFloat(s []float64, f func(float64) bool) bool
- func AllInt(s []int, f func(int) bool) bool
- func AllString(s []string, f func(string) bool) bool
- func AnyFloat(s []float64, f func(float64) bool) bool
- func AnyInt(s []int, f func(int) bool) bool
- func AnyString(s []string, f func(string) bool) bool
- func ByteCountBinary(b int64) string
- func ByteCountDecimal(b int64) string
- func ByteSliceFromString(str string) []byte
- func CutBytes(a []byte, from, to int) []byte
- func Delete(s interface{}, i int)
- func DurationToInt(duration, unit time.Duration) int
- func EqSlices(a, b interface{}) bool
- func EveryFloat(s []float64, f func(float64) bool) bool
- func EveryInt(s []int, f func(int) bool) bool
- func EveryString(s []string, f func(string) bool) bool
- func FileSizeStringToInt(s string) (int64, error)
- func FilterFloat(s []float64, f func(float64) bool) []float64
- func FilterInt(s []int, f func(int) bool) []int
- func FilterString(s []string, f func(string) bool) []string
- func FromBase64(s string) string
- func HasPrefix(s string, prefix string) bool
- func HasSuffix(s string, suffix string) bool
- func InSlice(v interface{}, s interface{}) bool
- func IndentedJSON(data interface{}) (*bytes.Buffer, error)
- func IndentedYAML(data interface{}) (*bytes.Buffer, error)
- func Index(s interface{}, t interface{}) int
- func Indexi(s []string, t string) int
- func InsertBytes(a []byte, i int, b []byte) []byte
- func InsertInStringSlice(a []string, index int, value string) []string
- func IntToFileSizeString(size, unit int) string
- func IsBool(s string) bool
- func IsCreditCard(s string) bool
- func IsEmail(s string) bool
- func IsFloat(s string) bool
- func IsHexColor(s string) bool
- func IsIP(s string) bool
- func IsInt(s string) bool
- func IsJSON(s string) bool
- func IsOnlyAlphaNumeric(s string) bool
- func IsOnlyDigits(s string) bool
- func IsOnlyLetters(s string) bool
- func IsRGB(s string) bool
- func IsStringEqual(s1 string, s2 string) bool
- func IsURL(s string) bool
- func LowerFirst(s string) string
- func MakeByteSlice(n int) []byte
- func MapFloat(s []float64, f func(float64) float64) []float64
- func MapInt(s []int, f func(int) int) []int
- func MapString(s []string, f func(string) string) []string
- func NormalizePath(p string) string
- func PathJoin(elem ...string) string
- func ReplaceBytes(a []byte, from, to int, new []byte) []byte
- func ReverseSort(s interface{})
- func ReverseString(s string) string
- func RoundUp(v uint64) uint64
- func Rsort(s interface{})
- func SomeFloat(s []float64, f func(float64) bool) bool
- func SomeInt(s []int, f func(int) bool) bool
- func SomeString(s []string, f func(string) bool) bool
- func StringFromByteSlice(bytes []byte) string
- func ToBase64(s string) string
- func ToCamelCase(s string) string
- func ToInt(s string) int
- func ToInt64(s string) int64
- func ToKebabCase(s string) string
- func ToPascalCase(s string) string
- func ToSnakeCase(s string) string
- func ToUint(s string) uint
- func Unique() string
- func UpperFirst(s string) string
- func Utoa(u uint) string
Constants ¶
const ( // Ki ... Ki = 1 << (10 * iota) // Mi ... Mi // Gi ... Gi // Ti ... Ti // Pi ... Pi // Ei ... Ei )
Binary prefixes for common use.
const ( MaxUint = ^uint(0) MaxInt = int(MaxUint >> 1) )
consts -
Variables ¶
var ( // ErrByteSliceTooLarge ... ErrByteSliceTooLarge = stacktrace.NewError("ByteSlice: too large") )
errors
Functions ¶
func AnyString ¶
AnyString returns true if one of the strings in the slice satisfies the predicate f
func ByteCountBinary ¶
ByteCountBinary returns a string representaion of bytes with a base of 2
func ByteCountDecimal ¶
ByteCountDecimal returns a string represenation of bytes with a base of 10
func ByteSliceFromString ¶
ByteSliceFromString converts a string into a slice of bytes without performing a copy. [NOTE] => This is an unsafe operation and may lead to problems if the bytes are changed.
func EqSlices ¶
func EqSlices(a, b interface{}) bool
EqSlices returns true if two slices are equal (not in-depth, for that use reflect.DeepEqual)
func EveryFloat ¶
EveryFloat returns true if all of the float64s in the slice satisfy the predicate f
func EveryString ¶
EveryString returns true if all of the strings in the slice satisfy the predicate f
func FileSizeStringToInt ¶
FileSizeStringToInt ...
func FilterFloat ¶
FilterFloat returns a new slice containing all float64s in the slice that satisfy the predicate f.
func FilterInt ¶
FilterInt returns a new slice containing all ints in the slice that satisfy the predicate f.
func FilterString ¶
FilterString returns a new slice containing all strings in the slice that satisfy the predicate f.
func InSlice ¶
func InSlice(v interface{}, s interface{}) bool
InSlice returns a boolean if the value is in the slice v = value to find s = slice
func IndentedJSON ¶
func IndentedYAML ¶
func Index ¶
func Index(s interface{}, t interface{}) int
Index returns the index of an element in a slice or -1 if not found
func InsertBytes ¶
InsertBytes new slice at specified position
func IsCreditCard ¶
IsCreditCard returns true if the provided string is a valid credit card
func IsHexColor ¶
IsHexColor returns true if the provided string is a valid HEX color
func IsOnlyAlphaNumeric ¶
IsOnlyAlphaNumeric returns true if the provided string is composed only by letters and numbers
func IsOnlyDigits ¶
IsOnlyDigits returns true if the provided string is composed only by numbers
func IsOnlyLetters ¶
IsOnlyLetters returns true if the provided string is composed only by letters
func LowerFirst ¶
LowerFirst returns a string with the first character lowercased
func MakeByteSlice ¶
MakeByteSlice allocates a slice of size n. If the allocation fails, it panics with ErrTooLarge.
func MapFloat ¶
MapFloat a new slice containing the results of applying the function f to each float64 in the original slice.
func MapInt ¶
MapInt a new slice containing the results of applying the function f to each int in the original slice.
func MapString ¶
MapString a new slice containing the results of applying the function f to each string in the original slice.
func NormalizePath ¶
func ReplaceBytes ¶
ReplaceBytes function unlike bytes.Replace allows you to specify range
func SomeFloat ¶
SomeFloat returns true if one of the float64s in the slice satisfies the predicate f
func SomeString ¶
SomeString returns true if one of the strings in the slice satisfies the predicate f
func StringFromByteSlice ¶
StringFromByteSlice converts a slice of bytes into a string without performing a copy. This is an unsafe operation and may lead to problems if the bytes passed as argument are changed while the string is used.
func Unique ¶
func Unique() string
Unique a unique token based on current time and crypted in sha256
func UpperFirst ¶
UpperFirst returns a string with the first character uppercased
Types ¶
This section is empty.