utils

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

README

util

业务工具包

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToString

func BytesToString(b []byte) string

BytesToString 字节切片转字符串

func ConcatString

func ConcatString(s ...string) string

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

func FileExists

func FileExists(path string) bool

func GenShortID

func GenShortID() (string, error)

GenShortID 生成一个id

func GetBytes

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

GetBytes interface 转 byte

func GetDate

func GetDate() string

GetDate 获取字符串日期

func GetHostname

func GetHostname() string

GetHostname 获取主机名

func GetInternalIP

func GetInternalIP() string

GetInternalIP get internal ip.

func GetLocalIP

func GetLocalIP() string

GetLocalIP 获取本地内网IP

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

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

IsZero 检查是否是零值

func JoinInt

func JoinInt(is []int64) string

JoinInt format int64 slice to string, eg: n1,n2,n3.

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 RemoveDuplicateElement

func RemoveDuplicateElement(slice []string) []string

func SliceShuffle

func SliceShuffle(slice []interface{})

SliceShuffle shuffle a slice

func SplitInt

func SplitInt(s string) ([]int64, error)

SplitInt split string into int64 slice.

func StrInArray

func StrInArray(str string, strArr []string) bool

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 StringToBytes

func StringToBytes(s string) []byte

StringToBytes convert string to byte

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

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

Pagination 分页器

func NewPagination

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

NewPagination 新建分页器

func (*Pagination) Pages

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