utils

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

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

Go to latest
Published: Feb 15, 2019 License: MIT Imports: 13 Imported by: 0

README

utils

Godoc Build Status

common functional utils for public

Table of Contents generated with DocToc

1. start

go get github.com/fwhezfwhez/utils

2. plugins

Most tools as global vals can be put into utils.Welcome to pull your request to fullfill the utils.

2.1 redis

util_redis

2.2 jwt

util_jwt

2.3 jsoncrack

util_jsoncrack

2.4 superchecker

util_superchecker

3. Notes:

3.1 All plugins should be inited well before the app starts,so we don't add locks to make it concurrently safe.Neither can we change global tools's properties while the app is running.
3.2 Add your plugins as you wish, but make sure a package with an init.go and at least a xxx_test.go file, when pull request is open, make sure travis-ci pass.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddJSONFormTag

func AddJSONFormTag(in string) string

AddJSONFormTag add json and form tag for a golang struct without tag and annotation

func FiltTag

func FiltTag(tag string) string

Get the tag's first value seperated by ','

func FindUpperElement

func FindUpperElement(s string) []string

FindUpperElement 找到字符串中大写字母的列表,附属于HumpToUnderLine

func HumpToUnderLine

func HumpToUnderLine(s string) string

HumpToUnderLine 驼峰转下划线

func IfZero

func IfZero(arg interface{}) bool

To judge a value whether zero or not. By the way, '%' '%%' is regarded as zero.

func In

func In(s string, arr []string) bool

s 是否in arr

func MD5

func MD5(rawMsg string) string

MD5 encrypt

func Obj2MapByJson

func Obj2MapByJson(obj interface{}) (map[string]interface{}, error)

Transer an obj to a map by json

func Obj2MapByReflect

func Obj2MapByReflect(obj interface{}) map[string]interface{}

Transer an obj to a map by reflect

func RetryHandler

func RetryHandler(n int, f func() (bool, error)) error

Execute a function n times, the function as the handler should be well format to func() (bool,error). Bool stands for its ok or not ,error stands for its error Example:

f := func() (bool, error) {
fmt.Println("connect to mysql")
return false, errors.New("time out")
}
if e := RetryHandler(3, f); e != nil {
	fmt.Println(e.Error())
}

func SmartPrint

func SmartPrint(i interface{}, escapeZero ...bool)

To well print a struct type value Example:

type User struct{
	Name string
	Age int
	Sal float64
	Friends []User
}
user := User{
Name:"ft",
Age: 9,
Sal: 1000,
Friends: []User{User{"f1" , 11, 0.,nil},{"f2" , 12, 0.,nil}},
}
SmartPrint(user)

If you want those zero value not print,use it like `SmartPrint(user, true)`

func Split

func Split(s string, sub string) []string

Split 增强型Split,对 a,,,,,,,b,,c 以","进行切割成[a,b,c]

func Split2

func Split2(s string, sub string, tmp *string, rs *[]string)

Split2 附属于Split,可独立使用

func TableToStruct

func TableToStruct(dataSource string, tableName string) string

postgres数据库表转go model 使用时注入驱动 _ "github.com/jinzhu/gorm/dialects/postgres"

func ToLimitOffset

func ToLimitOffset(sizeIn string, indexIn string, count int) (limit int, offset int)

generate limit offset by page size , page index , total count

func ToParam

func ToParam(vx interface{}, tag string) string

Convert a struct type value into a format string as a=x&&b=y&&c=z sorted by key asc like a=x&b=y&c=z not b=y,a=x,c=z

func ToString

func ToString(arg interface{}) string

Change arg to string if arg is a ptr kind, then change what it points to to string

func UnderLineToHump

func UnderLineToHump(s string) string

UnderLineToHump 下划线转驼峰

Types

type Column

type Column struct {
	ColumnNumber int    `gorm:"column_number"` // column index
	ColumnName   string `gorm:"column_name"`   // column_name
	ColumnType   string `gorm:"column_type"`   // column_type
}

数据库列属性

func FindColumns

func FindColumns(dataSource string, tableName string) []Column

根据数据源,表明获取列属性 使用时注入驱动 _ "github.com/jinzhu/gorm/dialects/postgres"

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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