ofutils

package module
v0.0.0-...-14b16bb Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: MIT Imports: 35 Imported by: 0

README

OFUtils

oldfeel 的 golang 工具库

Documentation

Index

Constants

View Source
const (
	// Info messages
	Info = 1 << iota // a == 1 (iota has been reset)

	// Warning Messages
	Warning = 1 << iota // b == 2

	// Error Messages
	Error = 1 << iota // c == 4
)

Variables

This section is empty.

Functions

func BackupRotation

func BackupRotation(options Options)

BackupRotation execute a rotation of file, daily,weekly and monthly

func ByteToMapArray

func ByteToMapArray(data [][]byte) []map[string]interface{}

func ChangeJson

func ChangeJson(data *[]byte, key string, value interface{}) error

func Compress

func Compress(tw *tar.Writer, path string) error

Compress compresses files into tar.gz file

func Copy

func Copy(dst, src string) error

func CopyDir

func CopyDir(src string, dst string) (err error)

CopyDir recursively copies a directory tree, attempting to preserve permissions. Source directory must exist, destination directory must *not* exist. Symlinks are ignored and skipped.

func CopyFile

func CopyFile(src, dst string) (err error)

CopyFile copies the contents of the file named src to the file named by dst. The file will be created if it does not already exist. If the destination file exists, all it's contents will be replaced by the contents of the source file. The file mode will be copied from the source and the copied data is synced/flushed to stable storage.

func Dial

func Dial(addr string) (*smtp.Client, error)

return a smtp client

func Exist

func Exist(filename string) bool

func FloatToString

func FloatToString(f float64) string

func GbkToUtf8

func GbkToUtf8(s []byte) ([]byte, error)

func GetDatabaseList

func GetDatabaseList(hostname string, bind string, username string, password string, verbosity int) []string

GetDatabaseList retrives list of databases on mysql

func GetEncryptPhone

func GetEncryptPhone(phone interface{}) string

func GetLocalIP

func GetLocalIP() string

GetLocalIP returns the non loopback local IP of the host

func GetStructName

func GetStructName(myvar interface{}) string

func GetTimeStamp

func GetTimeStamp() string

func GetWeekFirstDay

func GetWeekFirstDay() string

func ImageToBase64

func ImageToBase64(img image.Image) (string, error)

func IsNumeric

func IsNumeric(val interface{}) bool

func ListDirs

func ListDirs(rootpath string) []string

ListDirs give a Array of folders in a given path

func MD5

func MD5(text string) string

func MysqlBackup

func MysqlBackup(username, password, databases, mysqldumppath string)

func RandString

func RandString(n int) string

func SendMail

func SendMail(user, password, host, to, subject, body, mailtype string) error

func SendMailUsingTLS

func SendMailUsingTLS(addr string, auth smtp.Auth, from string,
	to []string, msg []byte) (err error)

参考net/smtp的func SendMail() 使用net.Dial连接tls(ssl)端口时,smtp.NewClient()会卡住且不提示err len(to)>1时,to[1]开始提示是密送

func SendQQMail

func SendQQMail(email, password, host string, port int, from, toEmail, subject, body string) error

func Sort

func Sort(list []orm.Params, key string) []orm.Params

func SubString

func SubString(str string, begin, length int) (substr string)

func ToBool

func ToBool(i int) bool

func ToFloat

func ToFloat(str interface{}) float64

func ToInt

func ToInt(val interface{}) int

func ToJson

func ToJson(datas interface{}) string

func ToString

func ToString(str interface{}) string

func TrimPrefix

func TrimPrefix(s, suffix string) string

func TrimSuffix

func TrimSuffix(s, suffix string) string

func Utf8ToGBK

func Utf8ToGBK(text string) string

func Utf8ToGbk

func Utf8ToGbk(s []byte) ([]byte, error)

func WriteToFile

func WriteToFile(filePath string, msg string)

WriteToFile create a file and writes a specified msg to it

func ZeroBefore

func ZeroBefore(i int) string

Types

type ByKey

type ByKey struct {
	Key  string
	List []orm.Params
}

func (ByKey) Len

func (a ByKey) Len() int

func (ByKey) Less

func (a ByKey) Less(i, j int) bool

func (ByKey) Swap

func (a ByKey) Swap(i, j int)

type Options

type Options struct {
	HostName          string
	Bind              string
	UserName          string
	Password          string
	Databases         []string
	ExcludedDatabases []string

	DatabaseRowCountTreshold int
	TableRowCountTreshold    int
	BatchSize                int
	ForceSplit               bool

	AdditionalMySQLDumpArgs string

	Verbosity              int
	MySQLDumpPath          string
	OutputDirectory        string
	DefaultsProvidedByUser bool
	ExecutionStartDate     time.Time

	DailyRotation   int
	WeeklyRotation  int
	MonthlyRotation int
}

Options model for commandline arguments

func GetOptions

func GetOptions(default_username, default_password, default_databases, default_mysqldumppath string) *Options

GetOptions creates Options type from Commandline arguments

func NewOptions

func NewOptions(hostname string, bind string, username string, password string, databases string, excludeddatabases string, databasetreshold int, tablethreshold int, batchsize int, forcesplit bool, additionals string, verbosity int, mysqldumppath string, outputDirectory string, defaultsProvidedByUser bool, dailyrotation int, weeklyrotation int, monthlyrotation int) *Options

NewOptions returns a new Options instance.

type Table

type Table struct {
	TableName string
	RowCount  int
}

Table model struct for table metadata

func GetTables

func GetTables(hostname string, bind string, username string, password string, database string, verbosity int) []Table

GetTables retrives list of tables with rowcounts

func NewTable

func NewTable(tableName string, rowCount int) *Table

NewTable returns a new Table instance.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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