xutils

package module
v0.0.0-...-92fafa5 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2024 License: MIT Imports: 23 Imported by: 0

README

xutils

utils lib for go language, eg. logs, zip and unzip file or folder, and so on

go replace:
https://studygolang.com/articles/27265

replace (
github.com/go-redsync/redsync/v4 => github.com/go-redsync/redsync/v4 v4.5.1
github.com/hashicorp/errwrap => github.com/hashicorp/errwrap v1.0.0
github.com/hashicorp/go-multierror => github.com/hashicorp/go-multierror v1.1.0
go.uber.org/atomic => go.uber.org/atomic v1.7.0
go.uber.org/multierr => go.uber.org/multierr v1.6.0
go.uber.org/zap => go.uber.org/zap v1.21.0
)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetClientAccessIP

func GetClientAccessIP(r *http.Request) string

GetClientAccessIP for nginx

func GetRoutineId

func GetRoutineId() string

func IPString2Long

func IPString2Long(ip string) (uint32, error)

func InitLogWrapper

func InitLogWrapper(maxFileSizeBytes int64, zipLog bool, out2stderr bool)

InitLogWrapper maxFileSizeBytes, 0 is set to 50MB zipLog, zip logs when write to file out2stderr, out to file default

func IpCidr2IpRange

func IpCidr2IpRange(ipCidr string) (ipStart, ipEnd string, err error)

func IsDebug

func IsDebug() bool

func Long2IPString

func Long2IPString(i uint32) (string, error)

func Md5sum

func Md5sum(src string) string

func OutDebugInfo

func OutDebugInfo() bool

func ReadDirAscByTime

func ReadDirAscByTime(name string) ([]os.DirEntry, error)

func ReadDirDescByTime

func ReadDirDescByTime(name string) ([]os.DirEntry, error)

func SetDebug

func SetDebug(debugMode bool)

func SetOutDebugInfo

func SetOutDebugInfo(outDebugInfo bool)

func UTCTime

func UTCTime() string

func UnZipTarGzFileToDir

func UnZipTarGzFileToDir(srcFile string, destDir string) error

func ZipFileToTarGz

func ZipFileToTarGz(srcFile string, destFile string) error

func ZipFileToTarGzWithLevel

func ZipFileToTarGzWithLevel(srcFile string, destFile string, zipLevel int) error

func ZipFilesToTarGz

func ZipFilesToTarGz(sliceSrcFile []string, destFile string) error

func ZipFilesToTarGzWithLevel

func ZipFilesToTarGzWithLevel(sliceSrcDir []string, destFile string, zipLevel int) error

ZipFilesToTarGzWithLevel zipLevel: -1 - 9, 0: no zip; 9: best zip, but slowest; -1: default level

Types

type CXLogFile

type CXLogFile struct {
	// contains filtered or unexported fields
}

func NewXLogFile

func NewXLogFile(logDir string, maxFileSize int64, zipLog bool) *CXLogFile

func (*CXLogFile) Write

func (x *CXLogFile) Write(p []byte) (n int, err error)

type LogFunc

type LogFunc func(...interface{})
var Debug LogFunc
var Err LogFunc
var Info LogFunc
var Warn LogFunc

type LogFuncf

type LogFuncf func(template string, args ...interface{})
var Debugf LogFuncf
var Errf LogFuncf
var Infof LogFuncf
var Warnf LogFuncf

type LogSpeedFunc

type LogSpeedFunc func(string, ...zap.Field)

type XRedisClient

type XRedisClient struct {
	// contains filtered or unexported fields
}

func NewXRedisClient

func NewXRedisClient(addr string, dbIndex int, pwd string, lockName string) (*XRedisClient, error)

func NewXRedisClusterClient

func NewXRedisClusterClient(addrs []string, pwd string, lockName string) (*XRedisClient, error)

func (*XRedisClient) Lock

func (x *XRedisClient) Lock(timeOut time.Duration) bool

func (*XRedisClient) Redis

func (*XRedisClient) UnLock

func (x *XRedisClient) UnLock(timeOut time.Duration) bool

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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