utils

package module
v1.0.22 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2021 License: MIT Imports: 24 Imported by: 1

README

golang 工具库

持续补充中...

Documentation

Index

Constants

View Source
const (
	DefaultLocal       = "Asia/Shanghai"
	DefaultDataTime    = "2006-01-02 15:04:05"
	DefaultData        = "2006-01-02"
	DefaultErrData     = "1000-01-01"
	DefaultErrDataTime = "1000-01-01 00:00:00"
)
View Source
const HOUR = 3600
View Source
const MINUTE = 60

Variables

View Source
var Visits uint64

记录访问次数

Functions

func Base64

func Base64(input string) string

func BirthdayToAge

func BirthdayToAge(birthday time.Time) uint8

生日计算年龄精确到日 周岁

func ConvertToBin

func ConvertToBin(num int) string

将十进制数字转化为二进制字符串

func DateTimeToTime

func DateTimeToTime(datetime string) time.Time

日期年月日时分秒 转 Time

func DateToTime

func DateToTime(date string) time.Time

日期年月日 转 Time 零点

func DbFieldJoin added in v1.0.17

func DbFieldJoin(fields []string) string

DbFieldJoin sql字段加引号和分隔号

func Decrement

func Decrement() uint64

减一

func EmptySliceStruct

func EmptySliceStruct() []struct{}

func EmptyStruct

func EmptyStruct() struct{}

返回空结构体

func FileExists added in v1.0.18

func FileExists(path string) bool

判断文件/文件夹是否存在,true存在,false不存在

func FileExt added in v1.0.18

func FileExt(f string) string

获取文件扩展名

func FileMTime added in v1.0.18

func FileMTime(file string) (int64, error)

获取文件修改时间

func FileSize added in v1.0.18

func FileSize(file string) (int64, error)

获取文件大小

func FiledDbType2GoType added in v1.0.17

func FiledDbType2GoType(fieldType string) string

FiledDbType2GoType db字段类型转go类型

func GeneratePassword

func GeneratePassword(userPassword string) ([]byte, error)

Deprecated 加密密码(太耗时,逐步废弃)

func GeneratePasswordNew

func GeneratePasswordNew(password, salt string) string

密码加密(新)

func GetArgsValue

func GetArgsValue(idx int, def string) string

func GetBoolEnv

func GetBoolEnv(key string) bool

布尔变量

func GetBoolEnvDefault

func GetBoolEnvDefault(key string, def bool) bool

func GetFreePort added in v1.0.19

func GetFreePort() (int, error)

GetFreePort 获取可用port

func GetIntEnv

func GetIntEnv(key string) int

整型变量

func GetIntEnvDefault

func GetIntEnvDefault(key string, def int) int

func GetIntranceIp

func GetIntranceIp() (string, error)

获取本机IPv4 IP,获取一个就返回

func GetStringEnv

func GetStringEnv(key string) string

字符串型变量

func GetStringEnvDefault

func GetStringEnvDefault(key string, def string) string

func GetStringSliceEnv

func GetStringSliceEnv(key string) []string

获取集群地址

func Hmacsha256

func Hmacsha256(s, key string) string

func HttpRequest

func HttpRequest(queryUrl string, method string, params map[string]string, headers map[string]string) ([]byte, error)

HttpRequest Deprecated 请调用request.NewHttpRequest()

func InSliceInt

func InSliceInt(v int, sl []int) bool

v是否包含在sl里

func InSliceString

func InSliceString(v string, sl []string) bool

v是否包含在sl里

func Increment

func Increment() uint64

加1

func IntSliceDiff

func IntSliceDiff(slice1, slice2 []int) (diffSlice []int)

比较slice,返回差集,slice1 在 slice2中没有的值

func IntSliceIntersect

func IntSliceIntersect(slice1, slice2 []int) (diffslice []int)

比较slice,返回交集

func IntSliceJoin

func IntSliceJoin(a []int, delim string) string

整型切片组合为字符串

func IntSliceToArgs

func IntSliceToArgs(ids []int) []interface{}

[]int to []interface{}

func IntSliceUnique

func IntSliceUnique(a []int) (ret []int)

int slice去重

func IpInt2String

func IpInt2String(ipInt int) string

整型转换成字符串

func IpString2Int

func IpString2Int(ipString string) int64

字符串转换整型

func IsDir added in v1.0.18

func IsDir(path string) bool

判断是否为文件夹

func IsEmail

func IsEmail(email string) bool

是否是email

func IsFile added in v1.0.18

func IsFile(path string) bool

判断文件是否存在

func IsValidTime added in v1.0.21

func IsValidTime(start, end time.Time) bool

IsValidTime 是否有效期

func MarkBankCard

func MarkBankCard(str string) string

银行卡号 格式:前6后4 示例:621483******3553

func MarkEmail

func MarkEmail(str string) string

邮箱 格式:前1后1 示例:b**n@gmail.com

func MarkIDCard

func MarkIDCard(str string) string

身份证号 格式:前10后4 示例:3212811989****0931

func MarkMobile

func MarkMobile(str string) string

手机号 格式:前3后4 示例:135****1436

func MarkPassWord

func MarkPassWord() string

密码 ******

func MarkRealName

func MarkRealName(str string) string

姓名 格式:隐姓 示例:*建文

func Md5

func Md5(str string) string

func NowDatetime

func NowDatetime() string

当前时间

func NowTime

func NowTime() time.Time

当前Time

func NowTimestamp

func NowTimestamp() int64

当前时间戳

func OpenFile

func OpenFile(filename string) (*os.File, error)

func RandNumString

func RandNumString(n int) string

随机纯数字

func RandString

func RandString(n int) string

随机字符串

func RandomRangeInt

func RandomRangeInt(min, max int) int

范围随机[min, max)

func RemoveSliceElement

func RemoveSliceElement(sl []int, v int) []int

删除Slice指定元素

func SetZipHeader

func SetZipHeader(headerSetter HeaderSetter, topic string)

设置文件下载头

func Sha256

func Sha256(s string) string

func StringSliceToArgs

func StringSliceToArgs(strs []string) []interface{}

[]string to []interface{}

func StringSliceUnique

func StringSliceUnique(a []string) (ret []string)

string slice去重

func TimestampToTime

func TimestampToTime(timestamp int64) time.Time

时间戳 转 Time

func ToCamel

func ToCamel(s string) string

字符串转大驼峰

func ToLowerCamel

func ToLowerCamel(s string) string

字符串转小驼峰

func TodayStartEndTime added in v1.0.19

func TodayStartEndTime() (time.Time, time.Time)

今天开始/结束时间

func ValidatePassword

func ValidatePassword(userPassword string, hashed string) (isOk bool, err error)

Deprecated 验证密码(太耗时,逐步废弃)

func ValidatePasswordNew

func ValidatePasswordNew(password, hashed, salt string) bool

验证密码(新)

func WFormatDuration

func WFormatDuration(t int) string

秒 转 时分秒

func ZipFile

func ZipFile(files []File, filename string)

压缩文件

Types

type File

type File struct {
	Name string
	Body []byte
}

type HeaderSetter

type HeaderSetter interface {
	Header(string, string)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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