utils

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2022 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

GPS 定位计算距离

异步执行

*

  • @Author cc
  • @Date 2021/4/1 10:41
  • @Description $ 钉钉群预警 *

email send

token

IP地址

*

  • @Author cc
  • @Date 2021/4/1 10:27
  • @Description $ 条件随机 *

常见的正则表达式

string

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertInterfaceToMap

func ConvertInterfaceToMap(src interface{}) (dest map[string]interface{}, isMap bool)

interface{} 转化为 map

func CreateToken

func CreateToken(user *UserInfo) (tokens string, err error)

创建token

func DateDay

func DateDay() (day int)

获取当前的日

func DateDayFormat

func DateDayFormat() string

func DateDayMilliseconds

func DateDayMilliseconds() (r int64)

Time stamp for the morning of the day: in milliseconds DateDayMilliseconds 获取当日凌晨时间戳(毫秒)

func DateDayZero

func DateDayZero() (r int64)

获取当日零时时间戳(秒) Time stamp of the morning of the day: unit seconds

func DayMi

func DayMi() (rr int64)

func Decimal added in v0.0.9

func Decimal(value float64) float64

func DeleteHashKey

func DeleteHashKey(hashKey string, keys ...string) error

* 删除 hash key 删除其中的key

func DeleteRedis

func DeleteRedis(key string) error

func DuplicateRemoval added in v0.0.9

func DuplicateRemoval(a []int64) []int64

int64

func EarthDistance added in v0.0.7

func EarthDistance(lat1, lng1, lat2, lng2 float64) float64

func Email

func Email(email string) (b bool)

判断邮箱是否正确 正确为true 错误为false

func EmailCode

func EmailCode(email string) (code string, err error)

func Encryption

func Encryption(password string, salt string) string

密码和盐加密存入数据库

func Equals

func Equals(a, b interface{}) (bool, error)

对比两者是否相等

func Float64ToString added in v0.0.9

func Float64ToString(f float64) string

func GenValidateCode

func GenValidateCode(width int) string

随机取出一定长度的随机数字

func GetBinAbsPath

func GetBinAbsPath() string

GetBinAbsPath 获取当前运行路径

func GetExternal

func GetExternal() string

获取外网IP地址

func GetHashInt64

func GetHashInt64(hashKey string, key string) (ret int64, err error)

func GetHashString

func GetHashString(hashKey string, key string) (ret string, err error)

** hash key in key get value (string)

func GetLocalIPAddress

func GetLocalIPAddress() string

获取本地IP地址

func GetOpId

func GetOpId(vv interface{}) (ret interface{})

获取值

func GetPoint added in v0.0.9

func GetPoint(points ...int) int

GetPoint 获取点数

func GetStringByKey

func GetStringByKey(key string) (value string, err error)

通过key获取value (type String)

func GetStringOrder

func GetStringOrder() (order string)

func GetWeek

func GetWeek() (week int64)

获取今天周

func Getint64Order

func Getint64Order() (order int64)

func Int32ToStr added in v0.0.9

func Int32ToStr(src int32) string

Int32ToStr int32转到string

func Int64ToStr added in v0.0.9

func Int64ToStr(src int64) string

Int64ToStr int64转到string

func Int64TurnString

func Int64TurnString(pr int64) string

int64 转 string

func IntArrayToString added in v0.0.9

func IntArrayToString(p []int32) string

func IntToStr added in v0.0.9

func IntToStr(i int) string

IntToStr int转到string

func IntTurnString

func IntTurnString(pr int) string

int 转 string

func Intercept

func Intercept(parameter string, condition string) string

func InterfaceTurnString

func InterfaceTurnString(pr interface{}) string

interface 转 string

func IsNull

func IsNull(str string) (bool bool)

判断是否为空 输入:"" 输出:false 输入:长度等于0 输出:false 输入:"1" 输出:true

func JsonToMap

func JsonToMap(jsonStr string) (map[string]interface{}, error)

JsonToMap

func LatitudeLongitudeDistance added in v0.0.7

func LatitudeLongitudeDistance(lon1, lat1, lon2, lat2 float64) (distance float64)

func MapToJson

func MapToJson(m map[string]interface{}) (string, error)

MapToJson map 转 Json Json 通过第三方工具 (https://www.sojson.com/json/json2go.html) {"code":200,"data":{"age":19,"user":"lcc"},"massge":"ok"} TestMapToJson

func MapTurnStruct

func MapTurnStruct(m map[string]interface{}) (obj interface{}, err error)

map 转 struct

func Max

func Max(m map[string]int64) (key string)

去除最大的

func Md5V3

func Md5V3(m string) string

加密

func Min

func Min(m map[string]int64) (v string)

取出最小的value

func MonthlyTotal

func MonthlyTotal(year int, month int) (days int)

输入年月 计算一个月的总数

func Password

func Password(password string) (bools bool)

判断密码强度 正确为true 错误为false

func Phone

func Phone(phone string) (bools bool)

判断号码是否正确 正确为true 错误为false

func RandomSection added in v0.0.9

func RandomSection(probability []int64) (section int)

总和==1000 的数组 返回概率数组下标(下标从0开始的)

func RandomString

func RandomString(length int) string

RandomString 在数字、大写字母、小写字母范围内生成num位的随机字符串

func RedisInit

func RedisInit(redisIp, redisPassword string, db int)

func RemoveDuplicatesAndEmpty

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

数组去重

func Reply

func Reply(email, title, content string) (err error)

func ResolveIPV4address

func ResolveIPV4address(ip string) (country, area, city, Isp string, err error)

ResolveIPV4address 解析IPv4 国家、地区、城市、运行商、错误

func Salt

func Salt() (salt string, err error)

获取盐值

func Send added in v0.0.9

func Send(messageType, message string, isAtAll bool) error

Send("Error", " testaee", true)

func SetRedisHash

func SetRedisHash(hashKey string, key string, value interface{}) (err error)

设置值hash

func SetRedisString

func SetRedisString(key string, code interface{}) (err error)

redis 保存验证码 时间为 60秒

func SetRedisStringCode

func SetRedisStringCode(key string, code interface{}, expiration time.Duration) (err error)

redis 保存验证码 时间为 60秒

func SplitUtil

func SplitUtil(parameter string, condition string) []string

字符串分割 第一个参数为要分割的字符串,第二个参数为分割的条件 返回分割后的数组

func StrToInt added in v0.0.9

func StrToInt(src string) int

StrToInt string转到int

func StrToInt32 added in v0.0.9

func StrToInt32(src string) int32

StrToInt32 string转到int32

func StrToInt64 added in v0.0.9

func StrToInt64(src string) int64

StrToInt64 string转到int64

func StringToFloat64 added in v0.0.9

func StringToFloat64(s string) float64

func StringToInt64

func StringToInt64(s string) (t int64)

标准时间格式(秒)转换为int64时间戳

func StringTurnInt

func StringTurnInt(pr string) (r int, err error)

string 转 int

func StructuralTurnMap

func StructuralTurnMap(obj interface{}) map[string]interface{}

struct 转 map

func Substr

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

start:正数 - 在字符串的指定位置开始,超出字符串长度强制把start变为字符串长度

负数 - 在从字符串结尾的指定位置开始
0 - 在字符串中的第一个字符处开始

length:正数 - 从 start 参数所在的位置返回

负数 - 从字符串末端返回

func SwaggerJson

func SwaggerJson(swagger string) (v map[string]interface{})

取值

func TestHall added in v0.0.9

func TestHall()

func ToInt64

func ToInt64(value interface{}) (d int64, err error)

将任何数值转换为Int64

func ToInt64V2

func ToInt64V2(v interface{}) (d int64, err error)

类型断言转类型

func UnixTimeInt64

func UnixTimeInt64(q int64) (p int64)

返回值int64类型 时间戳(秒): time.Now().Unix()) 时间戳(纳秒): time.Now().UnixNano()) 时间戳(毫秒): time.Now().UnixNano()/1e6) 时间戳(纳秒转换为秒) time.Now().UnixNano()/1e9)

func UnixTimeString

func UnixTimeString(q int64) (p string)

返回值string类型 时间戳(秒): time.Now().Unix()) 时间戳(纳秒): time.Now().UnixNano()) 时间戳(毫秒): time.Now().UnixNano()/1e6) 时间戳(纳秒转换为秒) time.Now().UnixNano()/1e9)

func WeekOneAndWeekSevenTime

func WeekOneAndWeekSevenTime() (one int64, seven int64)

WeekOneAndWeekSevenTime 当前周一凌晨和周日最后时间戳

func WithStdLib added in v0.0.9

func WithStdLib(n int64) int64

WithStdLib 绝对值

Types

type Async

type Async struct {
	// contains filtered or unexported fields
}

Async 异步执行对象

func New

func New() Async

New 创建一个新的异步执行对象

func NewAsync

func NewAsync() Async

NewAsync 老版本的兼容

func (*Async) Add

func (a *Async) Add(name string, handler interface{}, params ...interface{}) bool

Add 添加异步执行任务 name 任务名,结果返回时也将放在任务名中 handler 任务执行函数,将需要被执行的函数导入到程序中 params 任务执行函数所需要的参数

func (*Async) Clean

func (a *Async) Clean()

Clean 清空任务队列.

func (*Async) Run

func (a *Async) Run() (chan map[string][]interface{}, bool)

Run 任务执行函数,成功时将返回一个用于接受结果的channel 在所有异步任务都运行完成时,结果channel将会返回一个map[string][]interface{}的结果。

type HallUserInfo added in v0.0.9

type HallUserInfo struct {
	Id   int64  `json:"id"`
	Nick string `json:"nick"`
	Age  int    `json:"age"`
}

func HallUserInfoGo added in v0.0.9

func HallUserInfoGo() []HallUserInfo

type IP

type IP struct {
	Country   string `json:"country"`
	CountryId string `json:"country_id"`
	Area      string `json:"area"`
	AreaId    string `json:"area_id"`
	Region    string `json:"region"`
	RegionId  string `json:"region_id"`
	City      string `json:"city"`
	CityId    string `json:"city_id"`
	Isp       string `json:"isp"`
}

type IPInfo

type IPInfo struct {
	Code int `json:"code"`
	Data IP  `json:"data"`
}

type IdWorker

type IdWorker struct {
	// contains filtered or unexported fields
}

func (*IdWorker) InitIdWorker

func (this *IdWorker) InitIdWorker(workerId, datacenterId int64) error

func (*IdWorker) NextId

func (this *IdWorker) NextId() (int64, error)

type IpApiCom

type IpApiCom struct {
	Status      string  `json:"status"`
	Country     string  `json:"country"`
	CountryCode string  `json:"countryCode"`
	Region      string  `json:"region"`
	RegionName  string  `json:"regionName"`
	City        string  `json:"city"`
	Zip         string  `json:"zip"`
	Lat         float64 `json:"lat"`
	Lon         float64 `json:"lon"`
	Timezone    string  `json:"timezone"`
	Isp         string  `json:"isp"`
	Org         string  `json:"org"`
	As          string  `json:"as"`
	Query       string  `json:"query"`
}

func TaoBaoAPI

func TaoBaoAPI(ip string) *IpApiCom

type NailRobot added in v0.0.9

type NailRobot struct {
	Msgtype string `json:"msgtype"`
	Text    struct {
		Content string `json:"content"`
	} `json:"text"`
	At struct {
		AtMobiles []string `json:"atMobiles"`
		IsAtAll   bool     `json:"isAtAll"`
	} `json:"at"`
}

type RedisUser added in v0.0.9

type RedisUser struct {
	Id     int64  `json:"id"`
	PropId string `json:"prop_id"`
}

func RedisGo added in v0.0.9

func RedisGo() []RedisUser

type UserAll added in v0.0.9

type UserAll struct {
	Id       int64  `json:"id"`
	Username string `json:"username"`
	PropId   string `json:"prop_id"`
	Nick     string `json:"nick"`
	Age      int    `json:"age"`
}

type UserInfo

type UserInfo struct {
	Id       int64  `json:"id"`
	UserName string `json:"user_name"`
	UserType int64  `json:"user_type"`
	RegionId int64  `json:"region_id"`
}

func ParseToken

func ParseToken(tokens string) (user *UserInfo, err error)

获取token中的结构体

Directories

Path Synopsis
阿里云 短信发送
阿里云 短信发送
服务注册中心 eureka
服务注册中心 eureka
二维码
二维码
alils
Package alils implements the SDK(v0.5.0) of Simple Log Service(abbr.
Package alils implements the SDK(v0.5.0) of Simple Log Service(abbr.
es
mongodb
mongodb
监听文件
监听文件
mysql
mysql
权重随机出结果 返回下标
权重随机出结果 返回下标
Package ratelimit provides an efficient token bucket implementation that can be used to limit the rate of arbitrary things.
Package ratelimit provides an efficient token bucket implementation that can be used to limit the rate of arbitrary things.
Package uuid provides implementation of Universally Unique Identifier (UUID).
Package uuid provides implementation of Universally Unique Identifier (UUID).

Jump to

Keyboard shortcuts

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