utils

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

*

  • @api post utils. *
  • User: yunshengzhu
  • Date: 2019-04-25
  • Time: 17:22

*

  • @api post utils. *
  • User: yunshengzhu
  • Date: 2019-03-15
  • Time: 10:34

*

  • @api post utils. *
  • User: yunshengzhu
  • Date: 2021/12/25
  • Time: 下午6:49

*

  • @api post utils. *
  • User: yunshengzhu
  • Date: 2022/1/5
  • Time: 下午1:07

Index

Constants

View Source
const (
	XForwardedFor = "X-Forwarded-For"
	XRealIP       = "X-Real-IP"
)
View Source
const (
	NUmStr  = "0123456789"
	CharStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
)
View Source
const DATE_FORMAT = "2006-01-02 15:04:05"
View Source
const DATE_FORMAT_HIS = "150405"
View Source
const DATE_FORMAT_MD = "0102"
View Source
const DATE_FORMAT_MDY = "01-02-06"
View Source
const DATE_FORMAT_MDYHIS = "01/02/2006 15:04:05"
View Source
const DATE_FORMAT_YDM = "01/02/2006"
View Source
const DATE_FORMAT_YM = "2006-01"
View Source
const DATE_FORMAT_YMD = "2006-01-02"
View Source
const DATE_FORMAT_YMD01 = "2006-1-02"
View Source
const DATE_FORMAT_YMD02 = "2006-1-2"
View Source
const DATE_FORMAT_YMD03 = "2006-01-2"
View Source
const DATE_FORMAT_YMD1 = "20060102"
View Source
const (
	PRERNG = 1024
)
View Source
const YYMMDDHHII_DATE_FORMAT = "2006-01-02 15:04"
View Source
const YYMMDDHHII_FORMAT = "0601021504"

Variables

View Source
var (
	ErrFormatInvalid      = errors.New("格式错误")
	ErrAddressInvalid     = errors.New("地址码错误")
	ErrBirthFormatInvalid = errors.New("出生日期格式错误")
	ErrBirthRangeInvalid  = errors.New("出生日期范围错误")
	ErrSumInvalid         = errors.New("校验和错误")
)
View Source
var (
	LCG chan uint32
)

Functions

func Age

func Age(id string) int

获取年龄.

func Bytes2str

func Bytes2str(b []byte) string

func CheckBirthday

func CheckBirthday(id string) int64

验证生日,返回生日string

func CreateOrderNumber

func CreateOrderNumber(num int) string

func CreatePwd added in v0.0.18

func CreatePwd(n int) string

func DataUnix

func DataUnix(str, format string) int64

func DateString

func DateString(s int64, format string) string

func DecodeData

func DecodeData(data, key string) (string, error)

解密数据 DES(ECB,PKCS5) + base64

func EncodeData

func EncodeData(data, key string) (string, error)

加密数据 DES(ECB,PKCS5) + base64

func FenToYuanFloat

func FenToYuanFloat(amount int64) float64

func FenToYuanFormat

func FenToYuanFormat(price int64) string

func FenToYuanStr

func FenToYuanStr(amount int64) string

func FloatDiv100

func FloatDiv100(amount float64) float64

func FloatDiv100Str

func FloatDiv100Str(amount float64) string

func FloatMul100

func FloatMul100(amount float64) float64

func FloatMul100Str

func FloatMul100Str(str string) string

func GCSummary

func GCSummary() string

func GetDataMonth

func GetDataMonth(timeObj time.Time, monthNum int) int64

func GetLocalIp added in v0.0.20

func GetLocalIp() (ipv4 string, err error)

func GetRandomStr

func GetRandomStr(num int) string

func GetRandomStrToken

func GetRandomStrToken(num int) string

func GetReplaceSql

func GetReplaceSql(str string) string

func GetReplaceSqlMysql

func GetReplaceSqlMysql(str string) string

func GetSerialNumber

func GetSerialNumber(fix string, userId int64, num int) string

func GetVerifyCode

func GetVerifyCode(num int) string

func ImportDataUnix

func ImportDataUnix(str string) int64

func Ip2long

func Ip2long(ipstr string) uint32

Ip2long 将 IPv4 字符串形式转为 uint32

func MyMd5

func MyMd5(str string) string

func NewRequestId added in v0.0.36

func NewRequestId() context.Context

func PM12

func PM12() int64

------------------------------------------------ 返回当天的0点

func ReadFile

func ReadFile(fileName string) ([]byte, error)

文件读取

func RemoteIp

func RemoteIp(req *http.Request) string

RemoteIp 返回远程客户端的 IP,如 192.168.1.1

func Sex

func Sex(id string) string

获取性别.

func SharpClock

func SharpClock() int64

------------------------------------------------ 返回当前的整点时间

func Str2bytes

func Str2bytes(s string) []byte

func StrArrToInt64

func StrArrToInt64(list []string) (oList []int64, err error)

func StrToDate

func StrToDate(str, format string) time.Time

func Substr

func Substr(str string, start, length int) string

func TimeSprintf

func TimeSprintf(d time.Duration) string

short string format

func ToH

func ToH(bytes uint64) string

func UnixPM12

func UnixPM12() int64

func Validate

func Validate(id string) (flag bool, err error)

校验

func ValidateArea

func ValidateArea(id string) error

校验地区码

func ValidateBirth

func ValidateBirth(id string) error

校验生日,包括格式和范围

func ValidateReg

func ValidateReg(id string) error

整体校验格式

func ValidateSum

func ValidateSum(id string) error

校验 校验和

func YuanToFenFloat

func YuanToFenFloat(amount float64) int64

func YuanToFenStr

func YuanToFenStr(amount string) (int64, error)

Types

type RegexCheck

type RegexCheck struct {
}

func (*RegexCheck) CheckPwd

func (ic *RegexCheck) CheckPwd(str string) bool

验证密码格式 必须包含大写字母和数字

func (*RegexCheck) IsCellphone

func (ic *RegexCheck) IsCellphone(str ...string) bool

phone (不带前缀)最高11位

func (*RegexCheck) IsDecimals

func (ic *RegexCheck) IsDecimals(str ...string) bool

纯小数

func (*RegexCheck) IsEmail

func (ic *RegexCheck) IsEmail(str ...string) bool

邮箱

func (*RegexCheck) IsEngishLowCase

func (ic *RegexCheck) IsEngishLowCase(str ...string) bool

仅小写

func (*RegexCheck) IsEnglish

func (ic *RegexCheck) IsEnglish(str ...string) bool

大小写混合

func (*RegexCheck) IsEnglishCap

func (ic *RegexCheck) IsEnglishCap(str ...string) bool

仅大写

func (*RegexCheck) IsID

func (ic *RegexCheck) IsID(str ...string) bool

数字+字母 不限制大小写 6~30位

func (*RegexCheck) IsInteger

func (ic *RegexCheck) IsInteger(str ...string) bool

int

func (*RegexCheck) IsLen

func (ic *RegexCheck) IsLen(str string, min, max int) bool

func (*RegexCheck) IsPwd

func (ic *RegexCheck) IsPwd(str ...string) bool

数字+字母+符号 8~20位

func (*RegexCheck) IsTelephone

func (ic *RegexCheck) IsTelephone(str ...string) bool

telephone(不带前缀) 最高8位

Jump to

Keyboard shortcuts

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