Documentation
¶
Index ¶
- func BeginGormTx() *gorm.DB
- func BytesEqual(a, b []byte) bool
- func CommitGormTx(tx *gorm.DB) error
- func FilterOne[T any](s []T, fn func(T) bool) (t T)
- func HashArrayToArrays[T any](input []T, count int) [][]T
- func InitGorm(host string, port int64, user, password, db_name string) (err error)
- func Map[T any, T2 any](s []T, fn func(t T) (T2, error)) (t2 []T2, err error)
- func NewGormSession() *gorm.DB
- func ReadFileBytes(filePath string) ([]byte, error)
- func ReadFileHash(data []byte) (string, error)
- func TruncateString(v string, start, end int) string
- func UniqueAppend[S ~[]E, E comparable](s S, v E) S
- func ValidateJsonUnmarshal(data []byte, v interface{}) error
- func ValidateStruct(v interface{}) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BeginGormTx ¶
func BytesEqual ¶ added in v0.0.8
func CommitGormTx ¶
func FilterOne ¶ added in v0.0.6
Returns the first element that meet the condition specified in a callback function.
func HashArrayToArrays ¶
Hash an array into a nested array
numArray := []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
splitArray := gm.HashArrayToArrays(numArray, 3)
fmt.Printf("new array: %v\n", splitArray)
Output: [[1 4 7 9] [2 5 10] [3 6 8]]
func Map ¶
Calls a defined callback function on each element of an array, and returns an array that contains the results.
func StringArrayToNumberArray() {
var stringArray []string = []string{"1", "2", "3"}
numberArray, err := Map(stringArray, func(s string) (int64, error) {
return strconv.ParseInt(s, 10, 64)
})
if err != nil {
fmt.Println("string array to number array error, msg: ", err)
return
}
fmt.Println(numberArray)
}
func CalculateSquareValue() {
var numArray []int64 = []int64{2, 3, 4}
squareArray, _ := Map(numArray, func(n int64) (int64, error) {
return (n * n), nil
})
fmt.Println(squareArray)
}
func NewGormSession ¶
func ReadFileBytes ¶
func ReadFileHash ¶
Get the hash value of the file The effect is equivalent to the command line sha256sum
fileBytes, err := gm.ReadFileBytes("example.go")
if err != nil {
fmt.Printf("read file bytes err, msg: %v\n", err)
return
}
hash, err := gm.ReadFileHash(fileBytes)
if err != nil {
fmt.Printf("read file hash err, msg: %v\n", err)
return
}
fmt.Printf("hash: %v\n", hash)
-----------------------------------------------------
FILE_HASH=$(sha256sum example.go)
hash == FILE_HASH
func TruncateString ¶ added in v0.0.6
Truncate the string, keep the beginning and ends, and add an ellipsis in the middle to truncate the string
func UniqueAppend ¶ added in v0.0.7
func UniqueAppend[S ~[]E, E comparable](s S, v E) S
Only add the element if it is not already in the slice
func ValidateJsonUnmarshal ¶
Validate JSON data and parse it into the specified structure
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.