util

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2023 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Logger *logger = NewLogger("default")

Functions

func CheckPortIsReady

func CheckPortIsReady(addr string) (bool, error)

func CollectFieldNames added in v1.2.9

func CollectFieldNames(t reflect.Type, m map[string]struct{}, prefix string)

func Exec

func Exec(cmd string) (string, int)

func GetFilesBySuffix added in v1.3.1

func GetFilesBySuffix(dir, suffix string) ([]string, error)

get all files by suffix in a directory

func NewLogger

func NewLogger(tag string) *logger

func ParseWithPattern added in v1.3.1

func ParseWithPattern(pattern, str string) (map[string]string, error)

parse string use regexp pattern with group and return map

func Recover

func Recover()

func Render added in v1.3.1

func Render(tpl string, data interface{}) (string, error)

use go template to render string with map or list of map

Types

type DBUtil

type DBUtil struct {
}

func NewDBUtil

func NewDBUtil() *DBUtil

func (*DBUtil) CamelCaseToUdnderscore

func (u *DBUtil) CamelCaseToUdnderscore(s string) string

驼峰单词转下划线单词

func (*DBUtil) DoRecordQueryTableIds

func (u *DBUtil) DoRecordQueryTableIds(db *sql.DB, recorder map[string]mapset.Set, sql string, args []interface{})

func (*DBUtil) Dump

func (u *DBUtil) Dump(db *sql.DB, tables []string, w io.Writer)

func (*DBUtil) DumpFromRecordInfo

func (u *DBUtil) DumpFromRecordInfo(db *sql.DB, recorder map[string][]string) map[string][]string

func (*DBUtil) ExecSQL

func (u *DBUtil) ExecSQL(db *sql.DB, sqlStr string, args ...interface{}) (sql.Result, error)

func (*DBUtil) IntToPr

func (u *DBUtil) IntToPr(i int) *int

func (*DBUtil) ParseSQLText

func (m *DBUtil) ParseSQLText(sqlText string) []string

func (*DBUtil) QueryListBySQL

func (u *DBUtil) QueryListBySQL(db *sql.DB, sqlStr string, args ...interface{}) ([]map[string]interface{}, error)

func (*DBUtil) QueryObjectBySQL

func (u *DBUtil) QueryObjectBySQL(db *sql.DB, obj interface{}, sqlStr string, args ...interface{}) error

func (*DBUtil) QueryOneBySQL

func (u *DBUtil) QueryOneBySQL(db *sql.DB, sqlStr string, args ...interface{}) (map[string]interface{}, error)

func (*DBUtil) ReadFile

func (u *DBUtil) ReadFile(filePath string) string

func (*DBUtil) RunMySQLServer

func (u *DBUtil) RunMySQLServer(dbName string, dbPort int, block bool)

func (*DBUtil) SaveRecordToFile

func (u *DBUtil) SaveRecordToFile(dir string, recorder map[string][]string, overwrite bool)

func (*DBUtil) SelectToInsertSQLV1

func (u *DBUtil) SelectToInsertSQLV1(scope *gorm.Scope) (string, []string)

func (*DBUtil) SelectToInsertSQLV2

func (u *DBUtil) SelectToInsertSQLV2(db *gormv2.DB) (string, []string)

func (*DBUtil) StrToPr

func (u *DBUtil) StrToPr(s string) *string

func (*DBUtil) UderscoreToLowerCamelCase

func (u *DBUtil) UderscoreToLowerCamelCase(s string) string

下划线单词转为小写驼峰单词

func (*DBUtil) UderscoreToUpperCamelCase

func (u *DBUtil) UderscoreToUpperCamelCase(s string) string

下划线单词转为大写驼峰单词

type DSN

type DSN struct {
	*DSNValues
	// contains filtered or unexported fields
}

func Parse

func Parse(dsn string) (*DSN, error)

parses dsn string and returns DSN instance

func (*DSN) DSN

func (d *DSN) DSN(withSchema bool) string

return Host

func (*DSN) DatabaseName

func (d *DSN) DatabaseName() string

returns path

func (*DSN) Host

func (d *DSN) Host() string

return Host

func (*DSN) HostWithPort

func (d *DSN) HostWithPort() string

return Host

func (*DSN) Password

func (d *DSN) Password() string

returns Username

func (*DSN) Path

func (d *DSN) Path() string

returns path

func (*DSN) Port

func (d *DSN) Port() string

return Host

func (*DSN) Scheme

func (d *DSN) Scheme() string

return Scheme

func (*DSN) SetDatabaseName

func (d *DSN) SetDatabaseName(dbName string)

returns path

func (*DSN) User

func (d *DSN) User() *url.Userinfo

returns user

func (*DSN) Username

func (d *DSN) Username() string

returns Username

type DSNValues

type DSNValues struct {
	url.Values
}

DSN Values

func NewValues

func NewValues(query url.Values) (*DSNValues, error)

returns DSNValues from url.Values

func ParseQuery

func ParseQuery(query string) (*DSNValues, error)

Parses query and returns dsn values

func (*DSNValues) GetBool

func (d *DSNValues) GetBool(paramName string, defaultValue bool) bool

returns string value

func (*DSNValues) GetInt

func (d *DSNValues) GetInt(paramName string, defaultValue int) int

returns int value

func (*DSNValues) GetSeconds

func (d *DSNValues) GetSeconds(paramName string, defaultValue time.Duration) time.Duration

returns string value

func (*DSNValues) GetString

func (d *DSNValues) GetString(paramName string, defaultValue string) string

returns string value

Jump to

Keyboard shortcuts

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