goshared

package module
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2023 License: MIT Imports: 24 Imported by: 0

README

Introduction

This repo is my golang code collections, codes here maybe be written by myself or copied from other places. Some conventions are listed below:

  • The codes is classified by file name;
  • The codes that not rely on third-party libraries is placed in http.go, logic.go, os.go, string.go, crypto.go;
  • The codes that rely on third-party libraries is placed in mysql.go, redis.go, logrus.go;

Documentation

Overview

Package goshared ...

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AES256Decrypt

func AES256Decrypt(encryptedString string, keyString string) (decryptedString string)

func AES256Encrypt

func AES256Encrypt(stringToEncrypt string, keyString string) (encryptedString string)

func CheckFileExistence added in v1.4.0

func CheckFileExistence(filepath string) bool

CheckFileExistence ...

func FlatPath

func FlatPath(path string) []string

func FunctionName added in v1.5.0

func FunctionName() string

func GetFirstElementFromSliceByCondition added in v1.11.0

func GetFirstElementFromSliceByCondition[T any](in []T, condition func(element T) bool) (out T, ok bool)

GetFirstElementFromSliceByCondition ...

func IOMV

func IOMV(sourcePath, destPath string) error

IOMV Solve problem that os.Rename() give error "invalid cross-device link" in Docker container with Volumes(container FS and volume FS are different). Note that you need have permissions on both FS.

func InitLogrus added in v1.3.2

func InitLogrus(cfg LogrusRawConfig)

InitLogrus ...

func NewLogrusLogger added in v1.3.2

func NewLogrusLogger(cfg LogrusRawConfig) *logrus.Logger

func NewMysqlClient added in v1.3.2

func NewMysqlClient(rawCfg MysqlRawConfig, ormCfg MysqlORMConfig) (*gorm.DB, error)

func NewRedisClient added in v1.3.2

func NewRedisClient(ctx context.Context, cfg RedisRawConfig) (*redis.Client, error)

func NewSignalCtx

func NewSignalCtx() context.Context

NewSignalCtx generate context which work with SIGINT and SIGTERM

func ParseQuery

func ParseQuery(str string) (url.Values, error)

func RepeatedlyDo

func RepeatedlyDo(op func() error, rt uint) error

RepeatedlyDo do some operation at least once @Param op represent operation function which has 'func() error' signature @Param rt represent repeated times

func ShellMV

func ShellMV(src, dst string) error

ShellMV move file by exec shell command (Unix/Linux only)

func SliceContains added in v1.8.0

func SliceContains[T comparable](s []T, e T) bool

SliceContains ...

func SliceFilter added in v1.10.0

func SliceFilter[T any](in []T, condition func(element T) bool) (out []T)

SliceFilter ...

func SlicePaginate added in v1.10.0

func SlicePaginate[T any](in []T, offset *uint64, limit *uint64) (out []T)

SlicePaginate ...

func Ternary

func Ternary[T any](b bool, t, f T) T

Ternary if b == true return t else return f

Types

type FrequencyLimiter added in v1.9.0

type FrequencyLimiter func(ctx context.Context, op LimitedOperation) (done bool, err error)

func MakeFrequencyLimiter added in v1.9.0

func MakeFrequencyLimiter(period time.Duration, frequency uint64) FrequencyLimiter

MakeFrequencyLimiter ...

type LimitedOperation added in v1.9.0

type LimitedOperation func(context.Context) error

type LogrusRawConfig added in v1.3.2

type LogrusRawConfig struct {
	LogLevel  logrus.Level `envconfig:"-"`
	LogFile   string       `envconfig:"LOGRUS_LOG_FILE,optional"`
	LogCaller bool         `envconfig:"LOGRUS_LOG_CALLER,optional"`
}

type MysqlORMConfig added in v1.3.2

type MysqlORMConfig struct {
	MySQL mysql.Config
	GORM  gorm.Config
}

type MysqlRawConfig added in v1.3.2

type MysqlRawConfig struct {
	Host              string `envconfig:"MYSQL_HOST,default=127.0.0.1"`
	Port              string `envconfig:"MYSQL_PORT,default=3306"`
	TLP               string `envconfig:"MYSQL_TLP,optional"`
	User              string `envconfig:"MYSQL_USER"`
	Password          string `envconfig:"MYSQL_PASSWORD"`
	Database          string `envconfig:"MYSQL_DATABASE"`
	ConnMaxLifeMinute int    `envconfig:"MYSQL_CONN_MAX_LIFE_MINUTE,default=3"`
	MaxOpenConns      int    `envconfig:"MYSQL_MAX_OPEN_CONNS,default=10"`
	MaxIdleConns      int    `envconfig:"MYSQL_MAX_IDLE_CONNS,default=10"`
}

type RedisRawConfig added in v1.3.2

type RedisRawConfig struct {
	Host     string `envconfig:"REDIS_HOST,default=127.0.0.1"`
	Port     string `envconfig:"REDIS_PORT,default=6379"`
	User     string `envconfig:"REDIS_USER,default=default"`
	Password string `envconfig:"REDIS_PASSWORD,optional"`
	Database int    `envconfig:"REDIS_DATABASE,default=0"`
}

Directories

Path Synopsis
mysql module
nonbuiltin module
mysql Module
redis module

Jump to

Keyboard shortcuts

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