gm

package module
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

README

go-modules

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BeginGormTx

func BeginGormTx() *gorm.DB

func CommitGormTx

func CommitGormTx(tx *gorm.DB) error

func FilterOne added in v0.0.6

func FilterOne[T any](s []T, fn func(T) bool) (t T)

Returns the first element that meet the condition specified in a callback function.

func HashArrayToArrays

func HashArrayToArrays[T any](input []T, count int) [][]T

func InitGorm

func InitGorm(host string, port int64, user, password, db_name string) (err error)

func Map

func Map[T any, T2 any](s []T, fn func(t T) (T2, error)) (t2 []T2, err error)

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 NewGormSession() *gorm.DB

func ReadFileBytes

func ReadFileBytes(filePath string) ([]byte, error)

func ReadFileHash

func ReadFileHash(data []byte) (string, error)

func TruncateString added in v0.0.6

func TruncateString(v string, start, end int) string

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 ValidateJsonUnmarshal(data []byte, v any) error

func ValidateStruct

func ValidateStruct(v any) error

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL