utils

package
v0.0.0-...-1ec2636 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const DEFAULT_CUR = 1
View Source
const DEFAULT_PS = 10
View Source
const PAGE_HASNEXT_KEY = "hasNext"
View Source
const PAGE_RES_NAME = "list"

Variables

This section is empty.

Functions

func AgeToBirthday

func AgeToBirthday(Age int) time.Time

func ArrTostring

func ArrTostring(v interface{}, sep string) string

将整数数组转为字符串,以逗号连接

func BirthdayToAge

func BirthdayToAge(birthday time.Time) int

func BuildLimit

func BuildLimit(cur, ps int) string

生成 分页limit 10,10 字符串

func BuildRange

func BuildRange(cur, ps, total int) (int, int)

生成redis分页

func BytesToUint32

func BytesToUint32(from []byte) (to uint32)

func CheckHashNext

func CheckHashNext(ps, len int) (hasNext int)

简要分页,获取是否有下一页,简单判断获取数据是否等于请求数量

func ContainAnySubstr

func ContainAnySubstr(str string, substrs []string) bool

ContainAnySubstr: 输入string和一个slice的substring,给出这个string是否包含任何一个substring

func GenKey

func GenKey(sep string, keys ...interface{}) (key string)

生成公共串

func Join

func Join(v interface{}, sep string) (string, error)

func StringArrDiff

func StringArrDiff(a1, a2 []string) (diff []string)

求两个数组的差集,返回存在于a1却不存在a2中的值

func StringToUint32Arr

func StringToUint32Arr(str string, sep string) (r []uint32)

字符串分割并转化成数字数组

func SubString

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

字符串截取函数

参数:

str:带截取字符串
begin:开始截取位置
length:截取长度

func ToBool

func ToBool(v interface{}) (bool, error)

func ToFloat32

func ToFloat32(v interface{}) (float32, error)

func ToFloat64

func ToFloat64(v interface{}) (float64, error)

func ToInt

func ToInt(v interface{}) (int, error)

func ToInt16

func ToInt16(v interface{}) (int16, error)

func ToInt32

func ToInt32(v interface{}) (int32, error)

func ToInt64

func ToInt64(v interface{}) (int64, error)

func ToInt8

func ToInt8(v interface{}) (int8, error)

func ToString

func ToString(v interface{}) string

把interface类型转换成string类型

func ToStringSlice

func ToStringSlice(v interface{}) ([]string, error)

func ToUint

func ToUint(v interface{}) (uint, error)

func ToUint16

func ToUint16(v interface{}) (uint16, error)

func ToUint32

func ToUint32(v interface{}) (uint32, error)

func ToUint64

func ToUint64(v interface{}) (uint64, error)

func ToUint8

func ToUint8(v interface{}) (uint8, error)

func Uint32ArrDiff

func Uint32ArrDiff(a1, a2 []uint32) (diff []uint32)

求两个数组的差集,返回存在于a1却不存在a2中的值

func Uint32ArrIntersection

func Uint32ArrIntersection(a1, a2 []uint32) (both []uint32)

求两个数组的交集,返回存在于a1并且存在a2中的值

func Uint32ArrTostring

func Uint32ArrTostring(ids []uint32) string

将uint32的数组转为字符串,以逗号连接

func Uint32ToBytes

func Uint32ToBytes(from uint32) (to []byte)

要求to必须已经分配好空间

func UrlToShort

func UrlToShort(url_long string) (url_short string, e error)

Types

type PageRes

type PageRes struct {
	HasNext int         `json:"hasNext"`
	Start   string      `json:"start"`
	Ps      int         `json:"ps"`
	List    interface{} `json:"list"`
}

func FormatPageRes

func FormatPageRes(ps, len int, start string, data interface{}) (res PageRes)

构建包含list数据的分页结果

func FormatPages

func FormatPages(ps, len int) (pages PageRes)

获取分页结构

type Pages

type Pages struct {
	Cur   int `json:"cur"`   // 当前页
	Total int `json:"total"` // 总条数
	Ps    int `json:"ps"`    // 每页显示数量
	Pn    int `json:"pn"`    // 总页数
}

func PageInfo

func PageInfo(total, cur, ps int) *Pages

封装返回,获取分页信息

type SqlObj

type SqlObj interface {
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
	Exec(query string, args ...interface{}) (sql.Result, error)
}

Jump to

Keyboard shortcuts

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