utils

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2024 License: Apache-2.0 Imports: 31 Imported by: 52

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(x int) int

Abs 绝对数值

func Add

func Add(x, y interface{}, decimal float64, z ...interface{}) float64

Add 加法,两数及以上的数值累计相加之和,并保留小数点后两位 Example: Add(100, 2000, 2, 100.01111) Output: 2200.01

func Age

func Age(item AgeItem) (age uint, fmAge string)

Age 计算年龄

func AlphaDash

func AlphaDash(s string) bool

AlphaDash 字母和数字,下划线_及破折号-

func AlphaNum

func AlphaNum(s string) bool

AlphaNum 验证是否字母和数字

func ChsAlphaNum

func ChsAlphaNum(s string) bool

ChsAlphaNum 匹配汉字、字母、数字

func ChsDash

func ChsDash(s string) bool

ChsDash 匹配汉字、字母、数字特殊字符

func CountRunes

func CountRunes(s string) int

CountRunes 统计字符串字符长度

func CreateToken added in v1.0.4

func CreateToken(prefix string, other ...string) string

CreateToken 随机创建Token

func Decode

func Decode(buffer []byte, v interface{}) error

Decode JSON 解析返回的数据

func DecodeTo

func DecodeTo(buffer []byte) interface{}

DecodeTo JSON 转换数据格式

func DeviceFrom

func DeviceFrom(s string) string

DeviceFrom 设备平台,例如windows、iphone

func Div

func Div(x, y interface{}, decimal float64) float64

Div 除法, 两数相除 Example: Sub(999, 8989.5645, 2) Output: 0.11

func Float64

func Float64(any interface{}) float64

Float64 转换float64

func GenCombinations

func GenCombinations(values []string) [][]string

GenCombinations 生成数据集合 Example values := []string{`淘宝`,`美妆`,`双十一`} fmt.Println(GenCombinations(values, `-`)) Result: 淘宝 淘宝-美妆 淘宝-双十一 淘宝-美妆-双十一

func GenCombinationsString

func GenCombinationsString(values []string, sep string) []string

GenCombinationsString 生成数据集合 Example values := []string{`淘宝`,`美妆`,`双十一`} fmt.Println(GenCombinationsString(values, `-`)) Result: 淘宝 淘宝-美妆 淘宝-双十一 淘宝-美妆-双十一

func GenPasswordHash

func GenPasswordHash(password ...string) (string, string, error)

GenPasswordHash 生成Hash密码

func GetIp

func GetIp(ctx context.Context) string

GetIp 获取客户端IP

func GetMetaString added in v1.0.7

func GetMetaString(r *ghttp.Request, tag string) string

GetMetaString 获取Meta元数据类型属性值

func GetMetaVar added in v1.0.7

func GetMetaVar(r *ghttp.Request, tag string) *g.Var

GetMetaVar 获取MetaTag值

func HashMd5

func HashMd5(slices ...string) (string, error)

HashMd5 Md5加密

func HashMd5String

func HashMd5String(slices ...string) string

HashMd5String Md5加密字符串

func IsBase64

func IsBase64(s string) bool

IsBase64 验证字符串是否Base64格式

func IsEmail added in v1.0.10

func IsEmail(email string) bool

IsEmail 匹配邮件规则

func IsExpired added in v1.0.4

func IsExpired(expired string, d ...int64) error

IsExpired 验证时间是否到期

func IsHex

func IsHex(hex string) bool

IsHex 检测字符串是否十六进制

func IsMobile

func IsMobile(s string) bool

IsMobile 验证是否手机号

func IsPC

func IsPC(s string) bool

IsPC 是否PC端

func IsSeparator

func IsSeparator(r rune) bool

IsSeparator 返回一个布尔值,表示rune是否为分隔符

func IsSha256Hash

func IsSha256Hash(hash string) bool

IsSha256Hash 检测字符串是否HASH值

func MacString

func MacString(sep ...string) (string, error)

MacString 获取Mac地址字符串

func MobileDeviceAll

func MobileDeviceAll() []string

MobileDeviceAll 移动端设备

func Mul

func Mul(x, y interface{}, decimal float64, z ...interface{}) float64

Mul 乘法,两数及以上的数值乘积,并保留小数点后两位 Example: Mul(100, 2000, 2, 100.01111) Output: 2.0002222e+07

func MustMacString

func MustMacString(sep ...string) string

MustMacString 获取必须Mac地址

func NewAccount

func NewAccount(ps ...string) string

NewAccount 生成新账户

func NewArray

func NewArray(data interface{}) *sArray

NewArray 实例数组

func OrmWhereLeftLike added in v1.0.3

func OrmWhereLeftLike(s string) string

OrmWhereLeftLike 左匹配模糊查询

func OrmWhereLike added in v1.0.3

func OrmWhereLike(s string) string

OrmWhereLike 全文匹配查询

func OrmWhereRightLike added in v1.0.3

func OrmWhereRightLike(s string) string

OrmWhereRightLike 右模糊查询

func ParseHandlerFunc

func ParseHandlerFunc(r *ghttp.Request) *reflect.Value

ParseHandlerFunc 解析g.Meta元数据函数

func ParseUserAgentDevice

func ParseUserAgentDevice(s string) string

ParseUserAgentDevice 解析UserAgent设备消息

func PasswordHash

func PasswordHash(pwd string, salts ...string) (string, error)

PasswordHash Hash加密

func PasswordVerify

func PasswordVerify(pwdHash string, pwd string, salts ...string) bool

PasswordVerify 验证HASH密码有效性

func RandInt

func RandInt(n int) int

RandInt 根据数值长度获取区域范围内数值随机整数

func RandomInt

func RandomInt(minVal, maxVal int) int

RandomInt 自定义选取区域类随机数

func Scale

func Scale(s, decimal float64) float64

Scale 保留小数点-四舍五入算法 Example: Scale(98.88888, 2) 保留两位小数 Output: 98.89

func ScanIsEmpty

func ScanIsEmpty(errorMsg string) bool

ScanIsEmpty 扫描数据验证是否为空

func SeparatorStringToArray

func SeparatorStringToArray(s string) []string

SeparatorStringToArray 风格拆分字符串为数组字符串

func ShareFeeOrRate

func ShareFeeOrRate(item ShareFeeItem, addShareFee, addRate *float64) (shareFee, rate float64)

ShareFeeOrRate 计算分摊金额和比例

func SliceAddPrefix

func SliceAddPrefix(slice []string, prefix string) []string

SliceAddPrefix 字符串数组元素值添加前缀

func Slugify

func Slugify(path string, seps ...string) string

Slugify 转换URL路径为搜索引擎友好的字符串

func SmsReplaceVal

func SmsReplaceVal(s string, rplVal ...string) string

SmsReplaceVal 替换短信模板值

func SplitNonCharWords

func SplitNonCharWords(s string) []string

SplitNonCharWords 使用非字符(\W)作为分隔符来分割字符串,并去除结果中的空字符串

func SplitSymbolWords

func SplitSymbolWords(s string) []string

SplitSymbolWords 使用标点符号分割字符串

func StrPad added in v1.0.5

func StrPad(s string, length int, padStr byte, padType ...byte) string

StrPad 字符串填充

func Sub

func Sub(x, y interface{}, decimal float64, z ...interface{}) float64

Sub 减法,两数及以上的数值累计之差,并保留小数点后两位 Example: Sub(100, 2000, 2, 100.01111) Output: -2000.01

func Summary

func Summary(r *ghttp.Request) string

Summary 接口描述摘要

func Timestamp added in v1.0.4

func Timestamp(date string) (int64, error)

Timestamp 把时间转换为时间戳

func ToDayZeroDiff

func ToDayZeroDiff() time.Duration

ToDayZeroDiff 获取明天凌晨0点到当前时间的时间差

func ToSha256

func ToSha256(b []byte) string

ToSha256 转换为Sha256十六进制字符串

Types

type AgeItem

type AgeItem struct {
	Birthday string // 生日
	Type     int    // 类型:0默认年岁,1年月,2年月日, 3年月日时,4年月日时分
	IsFmt    bool   // 是否格式年月日:false默认格式化,true不格式化返回(岁数,不返月份和天数)
}

AgeItem 计算年龄

type IMac

type IMac struct {
	Mac  string
	Macs []string
}

IMac Net网络Mac地址

func GetMac

func GetMac() (iMac *IMac, err error)

GetMac 获取MAC地址

type ShareFeeItem

type ShareFeeItem struct {
	Total    float64 // 计算分摊总额,例如:优惠券抵扣金额
	TotalFee float64 // 计算比例总额,例如:商品总额
	UnitFee  float64 // 单价:商品单价
}

ShareFeeItem 计算分摊金额属性

Jump to

Keyboard shortcuts

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