utils

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2020 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TIME_FORMAT = "2006-01-02 15:04:05"
)

Variables

View Source
var (
	ErrPathIsNotAPath = errors.New("Not a path")
	ErrPathPerm       = errors.New("User has not perm to path")
)
View Source
var (
	CHAR_POOL = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
)

Functions

func BackupTable

func BackupTable(tableName string, v interface{}, db *gorm.DB, savePath string, version string) error

* Backup MySQL table rows into json file

@tableName: tableName, is not used for quering rows but as a part of json filename @v: slice pointer used for gorm resultset, this is where to implement generic type function @savePath: directory of where exported file located. @version: version of exporting. used as a part of the json filename

func DigitCaptchaGen

func DigitCaptchaGen() (string, string, error)

func DigitCaptchaVerify

func DigitCaptchaVerify(id string, answer string) bool

func DumpDatabase

func DumpDatabase(host, username, password, dbName, tableName, savePath, version string, port int) error

* Backup Database(or single table in it) using 'mysqldump' which must be pre-installed.

NOTICE: this function will block until done. You're able to delete 'cmd.Wait()' if you dont care the result and want a async execution, and mostly which is OKay.

func EnsureOpenFile

func EnsureOpenFile(full string) (*os.File, error)

func EnsurePath

func EnsurePath(path string) error

配置中的路径存在检查, 自动创建, 并执行权限检查

func ErrPanic

func ErrPanic(err error)

func Md5

func Md5(data []byte) string

func MemSet

func MemSet(p unsafe.Pointer, b byte, length uintptr)

func RandInt

func RandInt(max int) int

func RandIntScope

func RandIntScope(from, to int) int

func RandNumAlphaString

func RandNumAlphaString(length int) string

func RandNumString

func RandNumString(length int) string

func RestoreTable

func RestoreTable(filefull string, v interface{}, db *gorm.DB) error

TODO batch insertion

func Sha1

func Sha1(data []byte) string

func Sha256

func Sha256(data []byte) string

func TarGz

func TarGz(src, dest string) error

func UnTarGz

func UnTarGz(tarGz, dest string) error

func UnZip

func UnZip(zipFile, destPath string) error

func Unused

func Unused(v ...interface{})

func ValidPhoneCN

func ValidPhoneCN(phone string) bool

func ValidPhoneCNSimple

func ValidPhoneCNSimple(phone string) bool

func Zip

func Zip(fileOrDir, destFile string) error

Types

type Time

type Time time.Time

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

func (Time) String

func (t Time) String() string

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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