Documentation
¶
Index ¶
- func BeginGormTx() *gorm.DB
- 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 any) error
- func ValidateStruct(v any) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BeginGormTx ¶
func CommitGormTx ¶
func FilterOne ¶ added in v0.0.6
Returns the first element that meet the condition specified in a callback function.
func HashArrayToArrays ¶
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 ¶
func TruncateString ¶ added in v0.0.6
Cut off the beginning and end of the string and add ellipsis at both ends 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 ¶
func ValidateStruct ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.