Documentation
¶
Index ¶
- func CopyByte(b []byte) []byte
- func CopyStr(s string) string
- func EqualByte(a, b []byte) bool
- func ExtendByte(b []byte, needLen int) []byte
- func FileExt(fileName string) string
- func Getenv[V any](key string, init V) V
- func IncludeStr(slice []string, s string) bool
- func IndexOfStr(slice []string, s string) int
- func MD5(s string) string
- func PrependByte(dst []byte, src ...byte) []byte
- func PrependByteStr(dst []byte, src string) []byte
- func QuoteStr(raw string) string
- func RandByte(dst []byte) []byte
- func RandInt64(max int64) int64
- func ReflectType(obj interface{}) string
- func RenameFile(fileName, newName string) string
- func Sha256(args ...any) string
- func Token(object ...string) string
- func UnsafeBytes(s string) []byte
- func UnsafeStr(b []byte) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EqualByte ¶
EqualByte reports whether a and b are the same length and contain the same bytes. A nil argument is equivalent to an empty slice.
func ExtendByte ¶
ExtendByte extends b to needLen bytes.
Example b have [10 23 34 129], needLen 2. So return [10 23] Example b have [10 23 34 129], needLen 10. So return [10 23 34 129 0 0 0 0 0 0]
func FileExt ¶
FileExt Extract extension of file.
Eg Get `jpeg` from `https://902-local.s3.us-west-1.amazonaws.com/news/Avatar2023.jpeg` Or `63e85ba1.png` from `storage/tmp/63e85ba1.png`
func IncludeStr ¶
IncludeStr returns true or false if given string is in slice.
func IndexOfStr ¶
IndexOfStr returns index position in slice from given string If value is -1, the string does not found.
func PrependByte ¶
PrependByte prepends bytes into a given byte slice.
Example dst have [10 23 34] src is 44 54. So return [44 54 10 23 34]
func PrependByteStr ¶
PrependByteStr prepends a string into a given byte slice.
func RandByte ¶
RandByte returns dst with a cryptographically secure string random bytes.
NOTE: Make sure that dst has the length you need.
func RandInt64 ¶
RandInt64 Generate a random number Int64 in rang [0, max)
NOTE:
Get error `G404 (CWE-338): Use of weak random number generator (math/rand instead of crypto/rand) (Confidence: MEDIUM, Severity: HIGH)` when use `rand.Intn(max)` from "math/rand". Fixed Refer https://github.com/securego/gosec/issues/294#issuecomment-487452731
func ReflectType ¶
func ReflectType(obj interface{}) string
ReflectType Get the name of a struct instance.
func RenameFile ¶
RenameFile Extract new file path.
Eg Get `hello.jpeg` from `Avatar2023.jpeg` and `hello` Or `storage/tmp/hello.png` from `storage/tmp/63e85ba1.png` and `hello`
func UnsafeBytes ¶
UnsafeBytes returns a byte pointer without allocation.
Types ¶
This section is empty.