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 NewNumber[T number](v T) T
- func NewNumberPtr[T number](v T) *T
- func NewStringPtr(v string) *string
- func NewUint64[T number](v T) uint64
- 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
- type RedisClient
- func (redisClient *RedisClient) Client() *redis.Client
- func (redisClient *RedisClient) DBSize() *redis.IntCmd
- func (redisClient *RedisClient) Del(keys ...string) *redis.IntCmd
- func (redisClient *RedisClient) Get(key string) *redis.StringCmd
- func (redisClient *RedisClient) HDel(key string, field ...string) *redis.IntCmd
- func (redisClient *RedisClient) HExists(key string, field string) *redis.BoolCmd
- func (redisClient *RedisClient) HGet(key string, field string) *redis.StringCmd
- func (redisClient *RedisClient) HGetAll(key string) *redis.StringStringMapCmd
- func (redisClient *RedisClient) HKeys(key string) *redis.StringSliceCmd
- func (redisClient *RedisClient) HLen(key string) *redis.IntCmd
- func (redisClient *RedisClient) HSet(key string, value ...interface{}) *redis.IntCmd
- func (redisClient *RedisClient) Keys(parttern string) *redis.StringSliceCmd
- func (redisClient *RedisClient) MGet(keys ...string) *redis.SliceCmd
- func (redisClient *RedisClient) MSet(values ...interface{}) *redis.StatusCmd
- func (redisClient *RedisClient) NewTxPipeline() *RedisTxPipeline
- func (redisClient *RedisClient) Set(key string, value interface{}, expiration time.Duration) *redis.StatusCmd
- type RedisTxPipeline
- func (pipeline *RedisTxPipeline) Commit() ([]redis.Cmder, error)
- func (pipeline *RedisTxPipeline) Del(keys ...string) *redis.IntCmd
- func (pipeline *RedisTxPipeline) Get(key string) *redis.StringCmd
- func (pipeline *RedisTxPipeline) HDel(key string, field ...string) *redis.IntCmd
- func (pipeline *RedisTxPipeline) HExists(key string, field string) *redis.BoolCmd
- func (pipeline *RedisTxPipeline) HGet(key string, field string) *redis.StringCmd
- func (pipeline *RedisTxPipeline) HGetAll(key string) *redis.StringStringMapCmd
- func (pipeline *RedisTxPipeline) HKeys(key string) *redis.StringSliceCmd
- func (pipeline *RedisTxPipeline) HLen(key string) *redis.IntCmd
- func (pipeline *RedisTxPipeline) HSet(key string, value ...interface{}) *redis.IntCmd
- func (pipeline *RedisTxPipeline) Keys(parttern string) *redis.StringSliceCmd
- func (pipeline *RedisTxPipeline) MGet(keys ...string) *redis.SliceCmd
- func (pipeline *RedisTxPipeline) MSet(values ...interface{}) *redis.StatusCmd
- func (pipeline *RedisTxPipeline) Pipeliner() redis.Pipeliner
- func (pipeline *RedisTxPipeline) Set(key string, value interface{}, expiration time.Duration) *redis.StatusCmd
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 NewNumberPtr ¶ added in v0.0.18
func NewNumberPtr[T number](v T) *T
func NewStringPtr ¶ added in v0.0.18
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 ¶
type RedisClient ¶ added in v0.0.16
func InitRedis ¶ added in v0.0.16
func InitRedis[T number](ctx context.Context, username, password, address string, db T) (redisClient *RedisClient, err error)
func InitRedisFromURL ¶ added in v0.0.16
func InitRedisFromURL(ctx context.Context, url string) (redisClient *RedisClient, err error)
func (*RedisClient) Client ¶ added in v0.0.17
func (redisClient *RedisClient) Client() *redis.Client
Base Commands ------------------------------------------------------------------------------
func (*RedisClient) DBSize ¶ added in v0.0.17
func (redisClient *RedisClient) DBSize() *redis.IntCmd
func (*RedisClient) Del ¶ added in v0.0.16
func (redisClient *RedisClient) Del(keys ...string) *redis.IntCmd
func (*RedisClient) Get ¶ added in v0.0.16
func (redisClient *RedisClient) Get(key string) *redis.StringCmd
func (*RedisClient) HDel ¶ added in v0.0.16
func (redisClient *RedisClient) HDel(key string, field ...string) *redis.IntCmd
func (*RedisClient) HExists ¶ added in v0.0.16
func (redisClient *RedisClient) HExists(key string, field string) *redis.BoolCmd
func (*RedisClient) HGet ¶ added in v0.0.16
func (redisClient *RedisClient) HGet(key string, field string) *redis.StringCmd
func (*RedisClient) HGetAll ¶ added in v0.0.16
func (redisClient *RedisClient) HGetAll(key string) *redis.StringStringMapCmd
func (*RedisClient) HKeys ¶ added in v0.0.16
func (redisClient *RedisClient) HKeys(key string) *redis.StringSliceCmd
------------------------------------------------------------------------------
func (*RedisClient) HLen ¶ added in v0.0.16
func (redisClient *RedisClient) HLen(key string) *redis.IntCmd
func (*RedisClient) HSet ¶ added in v0.0.16
func (redisClient *RedisClient) HSet(key string, value ...interface{}) *redis.IntCmd
func (*RedisClient) Keys ¶ added in v0.0.16
func (redisClient *RedisClient) Keys(parttern string) *redis.StringSliceCmd
func (*RedisClient) MGet ¶ added in v0.0.16
func (redisClient *RedisClient) MGet(keys ...string) *redis.SliceCmd
func (*RedisClient) MSet ¶ added in v0.0.16
func (redisClient *RedisClient) MSet(values ...interface{}) *redis.StatusCmd
------------------------------------------------------------------------------
func (*RedisClient) NewTxPipeline ¶ added in v0.0.16
func (redisClient *RedisClient) NewTxPipeline() *RedisTxPipeline
type RedisTxPipeline ¶ added in v0.0.16
Redis Transaction Pipeline
func (*RedisTxPipeline) Commit ¶ added in v0.0.16
func (pipeline *RedisTxPipeline) Commit() ([]redis.Cmder, error)
func (*RedisTxPipeline) Del ¶ added in v0.0.16
func (pipeline *RedisTxPipeline) Del(keys ...string) *redis.IntCmd
func (*RedisTxPipeline) Get ¶ added in v0.0.16
func (pipeline *RedisTxPipeline) Get(key string) *redis.StringCmd
func (*RedisTxPipeline) HDel ¶ added in v0.0.16
func (pipeline *RedisTxPipeline) HDel(key string, field ...string) *redis.IntCmd
func (*RedisTxPipeline) HExists ¶ added in v0.0.16
func (pipeline *RedisTxPipeline) HExists(key string, field string) *redis.BoolCmd
func (*RedisTxPipeline) HGet ¶ added in v0.0.16
func (pipeline *RedisTxPipeline) HGet(key string, field string) *redis.StringCmd
func (*RedisTxPipeline) HGetAll ¶ added in v0.0.16
func (pipeline *RedisTxPipeline) HGetAll(key string) *redis.StringStringMapCmd
func (*RedisTxPipeline) HKeys ¶ added in v0.0.16
func (pipeline *RedisTxPipeline) HKeys(key string) *redis.StringSliceCmd
------------------------------------------------------------------------------
func (*RedisTxPipeline) HLen ¶ added in v0.0.16
func (pipeline *RedisTxPipeline) HLen(key string) *redis.IntCmd
func (*RedisTxPipeline) HSet ¶ added in v0.0.16
func (pipeline *RedisTxPipeline) HSet(key string, value ...interface{}) *redis.IntCmd
func (*RedisTxPipeline) Keys ¶ added in v0.0.16
func (pipeline *RedisTxPipeline) Keys(parttern string) *redis.StringSliceCmd
func (*RedisTxPipeline) MGet ¶ added in v0.0.16
func (pipeline *RedisTxPipeline) MGet(keys ...string) *redis.SliceCmd
func (*RedisTxPipeline) MSet ¶ added in v0.0.16
func (pipeline *RedisTxPipeline) MSet(values ...interface{}) *redis.StatusCmd
------------------------------------------------------------------------------
func (*RedisTxPipeline) Pipeliner ¶ added in v0.0.17
func (pipeline *RedisTxPipeline) Pipeliner() redis.Pipeliner