utils

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2024 License: MIT Imports: 22 Imported by: 1

README

util

业务工具包

Documentation

Index

Constants

View Source
const (
	// DateTime date time layout
	DateTime = "2006-01-02 15:04:05"
	// DateOnly date layout
	DateOnly = "2006-01-02"
	// TimeOnly time layout
	TimeOnly = "15:04:05"
)

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 ConcatStringBySlash added in v1.8.0

func ConcatStringBySlash(s ...string) string

ConcatStringBySlash concat string by slash

func Extract

func Extract(hostPort string, lis net.Listener) (string, error)

Extract returns a private addr and port.

func ExtractHostPort

func ExtractHostPort(addr string) (host string, port uint64, err error)

ExtractHostPort from address

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

func GetHostname() string

GetHostname 获取主机名

func GetInternalIP

func GetInternalIP() string

GetInternalIP get internal ip.

func GetLocalIP

func GetLocalIP() string

GetLocalIP 获取本地内网IP

func GetQiNiuPublicAccessURL

func GetQiNiuPublicAccessURL(cdnURL, path string) string

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

func GetRealIP

func GetRealIP(r *http.Request) (ip string)

GetRealIP get user real 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 Port

func Port(lis net.Listener) (int, bool)

Port return a real port.

func PrintStackTrace added in v1.7.0

func PrintStackTrace(msg string, err interface{}) string

PrintStackTrace print stack info

func RandomStr

func RandomStr(n int) string

RandomStr 随机字符串

func RegexpReplace

func RegexpReplace(reg, src, temp string) string

RegexpReplace ...

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 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