utils

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2021 License: MIT Imports: 17 Imported by: 0

README

util

业务工具包

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConcatString added in v1.3.0

func ConcatString(s ...string) string

ConcatString 连接字符串 NOTE: 性能比fmt.Sprintf和+号要好

func GenShortID

func GenShortID() (string, error)

GenShortID 生成一个id

func GetAvatarURL

func GetAvatarURL(cdnURL, key string) string

GetAvatarURL user's avatar, if empty, use default avatar

func GetBytes

func GetBytes(key interface{}) ([]byte, error)

GetBytes interface 转 byte

func GetDate

func GetDate() string

GetDate 获取字符串日期

func GetDefaultAvatarURL

func GetDefaultAvatarURL(cdnURL string) string

GetDefaultAvatarURL 获取默认头像

func GetHostname added in v1.3.1

func GetHostname() string

GetHostname 获取主机名

func GetQiNiuPublicAccessURL

func GetQiNiuPublicAccessURL(cdnURL, path string) string

GetQiNiuPublicAccessURL 获取七牛资源的公有链接 无需配置bucket, 域名会自动到域名所绑定的bucket去查找

func GetShowTime

func GetShowTime(ts time.Time) string

GetShowTime 格式化时间

func GetTodayDateInt

func GetTodayDateInt() int

GetTodayDateInt 获取整形的日期

func IsEmpty

func IsEmpty(s string) bool

IsEmpty 是否是空字符串

func IsInSlice

func IsInSlice(value interface{}, sli interface{}) bool

IsInSlice 判断某一值是否在slice中 因为使用了反射,所以时间开销比较大,使用中根据实际情况进行选择

func IsZero added in v1.3.1

func IsZero(i ...interface{}) bool

IsZero 检查是否是零值

func Md5

func Md5(str string) (string, error)

Md5 字符串转md5

func RandomStr

func RandomStr(n int) string

RandomStr 随机字符串

func RegexpReplace

func RegexpReplace(reg, src, temp string) string

RegexpReplace ...

func SliceShuffle added in v1.2.2

func SliceShuffle(slice []interface{})

SliceShuffle shuffle a slice

func StringSliceContains

func StringSliceContains(ss []string, s string) bool

StringSliceContains 字符串切片中是否包含另一个字符串 来自go源码 net/http/server.go

func StringSliceEqual

func StringSliceEqual(a, b []string) bool

StringSliceEqual 判断 string和slice 是否相等 使用了传统的遍历方式

func StringSliceReflectEqual

func StringSliceReflectEqual(a, b []string) bool

StringSliceReflectEqual 判断 string和slice 是否相等 因为使用了反射,所以效率较低,可以看benchmark结果

func StringToInt

func StringToInt(str string) (int, error)

StringToInt 字符串转int

func StringToInt64

func StringToInt64(str string) (int64, error)

StringToInt64 字符串转int64

func StringToUint64

func StringToUint64(str string) (uint64, error)

StringToUint64 字符串转uint64

func TimeLayout

func TimeLayout() string

TimeLayout 常用日期格式化模板

func TimeToShortString

func TimeToShortString(ts time.Time) string

TimeToShortString 时间转日期

func TimeToString

func TimeToString(ts time.Time) string

TimeToString 时间转字符串

func Uint64DeleteElemInSlice

func Uint64DeleteElemInSlice(i int, s []uint64) []uint64

Uint64DeleteElemInSlice 从slice删除元素 fast version, 会改变顺序 i:slice的索引值 s: slice

func Uint64DeleteElemInSliceWithOrder

func Uint64DeleteElemInSliceWithOrder(i int, s []uint64) []uint64

Uint64DeleteElemInSliceWithOrder 从slice删除元素 slow version, 保持原有顺序 i:slice的索引值 s: slice

func Uint64ShuffleSlice

func Uint64ShuffleSlice(a []uint64) []uint64

Uint64ShuffleSlice 对slice进行随机

func Uint64SliceReverse

func Uint64SliceReverse(a []uint64) []uint64

Uint64SliceReverse 对uint64 slice 反转

Types

type Pagination added in v1.3.1

type Pagination struct {
	Request  *http.Request
	Total    int
	PageSize int
}

Pagination 分页器

func NewPagination added in v1.3.1

func NewPagination(req *http.Request, total int, pageSize int) *Pagination

NewPagination 新建分页器

func (*Pagination) Pages added in v1.3.1

func (p *Pagination) Pages() string

Pages 渲染生成html分页标签

Jump to

Keyboard shortcuts

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