appx

package
v0.0.0-...-7681147 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2023 License: Apache-2.0 Imports: 42 Imported by: 0

README

数据类型处理函数

Documentation

Index

Constants

View Source
const (
	//RegularUserName 用户名
	RegularUserName = "^\\w{5,20}$"
	//RegularPassword 密码
	RegularPassword = "^\\.{5,32}$"
	//RegularIpAddress IP地址
	RegularIpAddress = "^([1-2]|)\\d{1,2}\\.([1-2]|)\\d{1,2}\\.([1-2]|)\\d{1,2}\\.([1-2]|)\\d{1,2}$"
	//RegularIpAddressPort IP:port
	RegularIpAddressPort = "^([1-2]|)\\d{1,2}\\.([1-2]|)\\d{1,2}\\.([1-2]|)\\d{1,2}\\.([1-2]|)\\d{1,2}\\:([1-6]|)\\d{0,4}$"
	//RegularIpAddressPortOrNot IP:port 或 IP
	RegularIpAddressPortOrNot = "^([1-2]|)\\d{1,2}\\.([1-2]|)\\d{1,2}\\.([1-2]|)\\d{1,2}\\.([1-2]|)\\d{1,2}((\\:([1-6]|)\\d{0,4})|)$"
)

#正则表达式返回,防止重复造轮子#

Variables

View Source
var RgxRules = map[string]string{
	"_RgxId":        "^\\d+$",
	"_RgxNum":       "^\\d+$",
	"_RgxStr":       "^\\w+$",
	"_RgxStrPlus":   "^[\\w+_-]+$",
	"_RgxTimeStamp": "^\\d{10,11}$",
	"_RgxMd5":       "^[a-fA-F0-9]{32}$",
	"_RgxSrvCode":   "^[a-zA-Z0-9_-]{1,50}$",
	"_RgxUser":      "^[a-zA-Z][a-zA-Z0-9_]{1,99}$",
	"_RgxPass":      "^.{0,50}$",
	"_RgxTimestamp": "^\\d{10,11}$",
	"_RgxTrueFalse": "^(1|0|true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO|ok|Ok|OK)$",
	"_RgxMail":      "^\\w[\\w\\d\\-\\_\\.]+@[\\w\\d\\-\\_\\.]+\\w$",
	"_RgxW":         "^[\\w\\d\\-\\_\\. ]+$",
	"_RgxURI":       "^(((ht|f)tps?):\\/\\/)?([^!@#$%^&*?.\\s-]([^!@#$%^&*?.\\s]{0,63}[^!@#$%^&*?.\\s])?\\.)+[a-z]{2,6}\\/?",
	"_RgxPhone":     "^[\\d\\(\\+ -]+$",
	"_RgxIp":        "^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$",
}

RgxRules 正则表达式

View Source
var Validate = validator.New()

Validate 创建校验器

Functions

func ArrFlipInt

func ArrFlipInt(s []int) []int

ArrFlipInt 翻转数组

func ArrayFilter

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

ArrayFilter 删除int数组里的空值

func ArrayFilterString

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

ArrayFilterString 删除string数组里的空值

func ArrayMergeStr

func ArrayMergeStr(a []string, b ...[]string) []string

ArrayMergeStr 合并string数组

func ArrayUnique

func ArrayUnique(arr []string) []string

ArrayUnique 保留数组中唯一值

func Base64Decode

func Base64Decode(str string) string

Base64Decode Base64解码 OK

func Base64Encode

func Base64Encode(str string) string

Base64Encode Base64转码 OK

func BytesJoin

func BytesJoin(pBytes ...[]byte) []byte

BytesJoin 多个[]byte合成一个

func BytesToUInt

func BytesToUInt(b []byte) (int, error)

BytesToUInt 字节转换成整形,字节数(大端)组转成int(无符号的)

func CertFormat

func CertFormat(key string, isPub bool) (cert string, err error)

CertFormat 格式化证书

func CheckAppID

func CheckAppID(f validator.FieldLevel) bool

CheckAppID 名称

func CheckChar

func CheckChar(f validator.FieldLevel) bool

CheckChar 验证备注

func CheckCnEnNum

func CheckCnEnNum(f validator.FieldLevel) bool

CheckCnEnNum 中英文数字

func CheckCnEnNumChar

func CheckCnEnNumChar(f validator.FieldLevel) bool

CheckCnEnNumChar 中英文数字常见字符

func CheckEgt0

func CheckEgt0(f validator.FieldLevel) bool

CheckEgt0 验证整数

func CheckEmail

func CheckEmail(f validator.FieldLevel) bool

CheckEmail 检查邮箱

func CheckEmptyString

func CheckEmptyString(keys map[string]string) string

CheckEmptyString 返回map里为空的键,逗号分隔

func CheckFloatStr

func CheckFloatStr(f validator.FieldLevel) bool

CheckFloatStr 验证float64

func CheckInt16

func CheckInt16(f validator.FieldLevel) bool

CheckInt16 验证整数

func CheckInt32

func CheckInt32(f validator.FieldLevel) bool

CheckInt32 验证整数

func CheckInt64

func CheckInt64(f validator.FieldLevel) bool

CheckInt64 验证整数

func CheckIntStr

func CheckIntStr(f validator.FieldLevel) bool

CheckIntStr 验证数字

func CheckKey

func CheckKey(f validator.FieldLevel) bool

CheckKey 验证Key

func CheckKeys

func CheckKeys(f validator.FieldLevel) bool

CheckKeys 验证Keys

func CheckKeyword

func CheckKeyword(f validator.FieldLevel) bool

CheckKeyword 验证关键字

func CheckMD5

func CheckMD5(f validator.FieldLevel) bool

CheckMD5 验证MD5

func CheckName

func CheckName(f validator.FieldLevel) bool

CheckName 名称

func CheckPassWd

func CheckPassWd(f validator.FieldLevel) bool

CheckPassWd 验证密码

func CheckPhone

func CheckPhone(f validator.FieldLevel) bool

CheckPhone 检查手机

func CheckRemark

func CheckRemark(f validator.FieldLevel) bool

CheckRemark 名称

func CheckRoute

func CheckRoute(f validator.FieldLevel) bool

CheckRoute 验证路由

func CheckText

func CheckText(f validator.FieldLevel) bool

CheckText 验证文本

func CheckTrueFalse

func CheckTrueFalse(f validator.FieldLevel) bool

CheckTrueFalse 验证是与否

func CheckUnionSn

func CheckUnionSn(f validator.FieldLevel) bool

CheckUnionSn 验证唯一标识

func CheckUrl

func CheckUrl(f validator.FieldLevel) bool

CheckUrl 验证url

func CheckUser

func CheckUser(f validator.FieldLevel) bool

CheckUser 验证用户名

func ChkInt

func ChkInt(t string, num int64) bool

ChkInt 检测字符串是否符合正则标准

func ChkStr

func ChkStr(t string, str string) bool

ChkStr 检测字符串是否符合正则标准

func CmdExecWindows

func CmdExecWindows(c string, cmdPath string) string

CmdExecWindows 执行cmd指令

func CreateDir

func CreateDir(p string) bool

CreateDir 创建文件夹

func CreateMultiDir

func CreateMultiDir(filePath string) error

CreateMultiDir 调用os.MkdirAll递归创建文件夹

func CreateUUID

func CreateUUID(up ...interface{}) string

CreateUUID 生成UUID NIL为小写

func DbFunc

func DbFunc(dbConfig string) *gorm.DB

DbFunc 初始化数据库

func DeBmUrlStr

func DeBmUrlStr(key string, str string) string

DeBmUrlStr 保命图片解析字符串

func DeStr

func DeStr(pass string, key string) string

DeStr 解密可解密字符串 OK

func DebugFunc

func DebugFunc(isOpen bool, ft func())

DebugFunc 只有在debug模式下执行的程序

func Die

func Die(t ...interface{})

Die 退出

func Duplicate

func Duplicate(a interface{}) (ret []interface{})

Duplicate map,数组列表去重

func E

func E(msg string) error

E 返回错误信息

func Echo

func Echo(a ...interface{})

func EchoFail

func EchoFail(str string)

EchoFail 失败输出

func EchoInfo

func EchoInfo(str string)

EchoInfo 信息输出

func EchoPlus

func EchoPlus(str string, color string, bg string, highLight string)

EchoPlus 带特效输出

func EchoSuccess

func EchoSuccess(str string)

EchoSuccess 成功输出

func EchoWarning

func EchoWarning(str string)

EchoWarning 警告输出

func Empty

func Empty(inStr interface{}) bool

Empty 判断字符串是否为空,去掉空格

func EnStr

func EnStr(pass string, key string) string

EnStr 生成可解密字符串 OK

func Err

func Err(e error)

Err 如果err不是nil打印err

func Error

func Error(err interface{}, exit bool)

Error 错误发生后是否退出 true是

func ExecCommand

func ExecCommand(name, sangS string) error

ExecCommand 执行命令

func ExitGoFunc

func ExitGoFunc(done chan int)

ExitGoFunc 退出协程

func ExplodeInt

func ExplodeInt(s string, sp string) (its []int)

ExplodeInt 根据字符分隔字符串为字符串数组,并删除空值

func ExplodeStr

func ExplodeStr(s string, sp string) []string

ExplodeStr 根据字符分隔字符串为字符串数组,并删除空值

func FileClear

func FileClear(Path string)

FileClear 清空文件内容

func FileGetContent

func FileGetContent(path string) (string, error)

FileGetContent 读取文件

func FileMd5

func FileMd5(path string) (string, error)

FileMd5 文件的MD5校验 OK

func FilePutContents

func FilePutContents(Path string, s string, types bool)

FilePutContents 写入文件,type=true覆盖,type=false追加

func FileSha256

func FileSha256(path string) (string, error)

FileSha256 文件的SHA256校验 OK

func FilterMapEmpty

func FilterMapEmpty(mp map[string]interface{}, ign []string) map[string]interface{}

FilterMapEmpty 过滤为空的map和忽略的map,保留不为空和忽略字段

func FilterStr

func FilterStr(strs []string) []string

FilterStr 删除字符串数组中的空值

func GbkToUtf8

func GbkToUtf8(src []byte) ([]byte, error)

func Get

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

Get Get请求(20秒超时)

func GetCountryByCode

func GetCountryByCode(code string) string

func GetCountryCode

func GetCountryCode(country string) string

func GetCpuId

func GetCpuId() string

GetCpuId 获取CPUID

func GetCurrentPath

func GetCurrentPath() (string, error)

GetCurrentPath 获取执行程序的绝对路径

func GetExpireTime

func GetExpireTime(sec int) string

GetExpireTime 获取过期N秒的时间 OK

func GetMac

func GetMac() string

GetMac 获取MAC

func GetMachineData

func GetMachineData() string

GetMachineData 获取机器码

func GetMaxProcess

func GetMaxProcess()

GetMaxProcess 获取CPU最大同时数量

func GetPlatformUUID

func GetPlatformUUID() string

GetPlatformUUID 获取平台号

func GetProcessByCmd

func GetProcessByCmd(cmd string) (pn *process.Process, e error)

GetProcessByCmd 根据cmd命令获取对应的pid

func GetRandPort

func GetRandPort() (port int)

GetRandPort 获取随机端口

func GetRelativePath

func GetRelativePath() (rootDir string, e error)

GetRelativePath 获取运行程序的相对路径

func GetSerialNumber

func GetSerialNumber() string

GetSerialNumber 获取机器序列号

func GetSn

func GetSn() string

GetSn 获取随机sn OK

func GetStringArrayRand

func GetStringArrayRand(s []string) (r string)

GetStringArrayRand 随机获取字符串数组中的一个值返回

func GetSysBit

func GetSysBit() int

GetSysBit 获取当前系统是32位还是64位

func GetTime10

func GetTime10() string

GetTime10 获取当前时间戳(10位) OK

func GetTime10Int

func GetTime10Int() int

GetTime10Int 获取当前时间戳(10位) OK

func GetTime13

func GetTime13() string

GetTime13 获取当前时间戳(13位) OK

func GetTime13Int

func GetTime13Int() int64

GetTime13Int 获取当前时间戳(13位) OK

func GormT

func GormT(dsn string, path string, pacName string) bool

GormT 转换数据库schema到go struct

func GzipCompress

func GzipCompress(s string) (r string, err error)

GzipCompress GZIP压缩字符串 OK

func GzipCompressByte

func GzipCompressByte(b []byte) (r string, err error)

GzipCompressByte GZIP压缩字符串 OK

func GzipUnCompress

func GzipUnCompress(s string) (result []byte, err error)

GzipUnCompress GZIP解压缩字符串 OK

func GzipUnCompressByte

func GzipUnCompressByte(s []byte) (result []byte, err error)

GzipUnCompressByte GZIP解压缩字符串 OK

func Implode

func Implode(delimiter string, arr []string) string

Implode 按照字符串数组拼接成需要的字符串

func ImplodeInt

func ImplodeInt(delimiter string, arr []int) string

ImplodeInt 按照整数数组拼接成需要的字符串

func InArray

func InArray(node interface{}, nodes interface{}) bool

InArray 判断是否在数组里

func InArrayInt

func InArrayInt(node int, nodes []int) bool

InArrayInt 判断是否在数组里 int

func InArrayStr

func InArrayStr(one string, arr []string) bool

InArrayStr 判断字符串元素是否在数组中存在

func InArrayString

func InArrayString(node string, nodes []string) bool

InArrayString 判断是否在数组里 string

func InitBaseApi

func InitBaseApi(bm []string, key string, oldSign string) (err error, uri string, sign string)

InitBaseApi 初始化获取域名

func IpIntToString

func IpIntToString(ipInt int) string

IpIntToString int类型的IP地址转换为正常IP地址

func IpMaskToInt

func IpMaskToInt(netmask string) (int, error)

IpMaskToInt 子网掩码转数字

func Ipv4MaskString

func Ipv4MaskString(m []byte) string

Ipv4MaskString byte格式IP转string

func IsExist

func IsExist(path string) bool

IsExist 判断文件夹或文件是否存在

func IsLanIp

func IsLanIp(ip string) bool

IsLanIp 判断IP是不是内网

func JsonMarshal

func JsonMarshal(st interface{}) []byte

JsonMarshal 结构体转换为json忽略错误

func JsonOk

func JsonOk(c *gin.Context, msg string, ret map[string]interface{}) bool

JsonOk gin版本返回

func JsonWrong

func JsonWrong(c *gin.Context, code int, msg string, ret map[string]interface{}) bool

JsonWrong gin版本返回

func KillPid

func KillPid(pid int)

KillPid 杀死指定pid的进程

func KillPidPPid

func KillPidPPid(pid int)

KillPidPPid 输入pid,杀死它和它所有的父级

func KillProcess

func KillProcess(name string, exp []int)

KillProcess 操作停止,排除exp里的

func MapExist

func MapExist(key string, mp map[string]string) bool

MapExist 判断map键值是否存在

func MapToQuery

func MapToQuery(m map[string]interface{}) string

MapToQuery map转get的参数

func Md5Byte

func Md5Byte(b []byte) (m []byte)

Md5Byte 生成MD5Byte OK

func Md5Lower

func Md5Lower(str string) string

Md5Lower 返回小写md5字符串 OK

func Md5Upper

func Md5Upper(str string) string

Md5Upper 返回大写md5字符串 OK

func MdDecode

func MdDecode(str string, key string, expSec int) string

MdDecode 梦蝶跨平台解密算法,expSec密钥有效期(秒) OK

func MdEncode

func MdEncode(str string, key string, expSec int) string

MdEncode 梦蝶跨平台加密算法,expSec密钥过期时间(秒) OK

func MdXor

func MdXor(str, key string) string

MdXor 异或az算法 OK

func MtRand

func MtRand(min, max int) int

MtRand 生成区间范围的随机整数 OK

func MyDate

func MyDate(Format interface{}, mds ...MyDateSt) string

MyDate 时间戳转换为字符串

func Now

func Now() int

Now 返回当前时间戳

func OpenTrans

func OpenTrans()

OpenTrans 开启Linux转发

func ParseInt

func ParseInt(s string) int

ParseInt 转换string为int

func ParseIpv4

func ParseIpv4(ip string) (string, int)

ParseIpv4 转换IP+端口为IP ,端口

func PathJoin

func PathJoin(p ...string) string

PathJoin 根据系统不同组合路径

func Pln

func Pln(a ...interface{})

Pln 打印

func Post

func Post(uri string, m interface{}) (string, error)

Post Post请求(20秒超时)

func PostTimeout

func PostTimeout(uri string, m interface{}, timeout time.Duration) (string, error)

PostTimeout POST请求带超时设置

func ProcessId

func ProcessId() (pid []int32)

ProcessId 获取所有进程id,以数组返回

func ProcessName

func ProcessName() (name []string)

ProcessName 获取所有进程名,以数组返回

func RandStr

func RandStr(k string, n int) string

RandStr 生成指定长度和类型(数字/字母/特殊字符)的随机字符串 OK

func RedisFunc

func RedisFunc(addr string, port int, password string, index int) *redis.Client

RedisFunc 初始化redis数据库

func RegValidate

func RegValidate()

RegValidate 注册校验

func RemoveAll

func RemoveAll(p string) bool

RemoveAll 删除文件夹

func ReqParam

func ReqParam(ctx *gin.Context, method string, p interface{}, rpe ...ReqParamExt) (b map[string]string, e error)

ReqParam

  • 获取Get或Post的参数,返回结构体的JSON格式
  • @param: ctx gin的上下文
  • @param: method POST/GET
  • @param: p 对应的结构体,结构体的TAG必须有json选项(如需返回map的key重命名则加入alias选项,传参读取的是json选项),如需控制格式,传入rgx选项,可以用预定模板或直接写表达式
  • @param: rpe 拓展参数,没有可以不填
  • @return:b 对应的map格式, e 是否成功
  • @author: bu
  • @date: 2021/11/22

func ReturnDetailProcess

func ReturnDetailProcess(content string) (pidI []int)

ReturnDetailProcess 杀死详细进程,返回pid的int类型数组

func Rsa2Private

func Rsa2Private(str string, key string, encode bool) (rs string, e error)

Rsa2Private RSA2私钥加解密 OK

func Rsa2Public

func Rsa2Public(str string, key string, encode bool) (rs string, e error)

Rsa2Public RSA2公钥加解密 OK

func SendMail

func SendMail(d SendMailSt) error

SendMail 邮件发送封装

func ShellExec

func ShellExec(c string, cmdShow bool, runtimeShow bool) string

ShellExec 执行shell,同步

func ShellExecEcho

func ShellExecEcho(c string) string

ShellExecEcho 执行shell,显示详情

func ShellExecEchoDisable

func ShellExecEchoDisable(c string) string

ShellExecEchoDisable 执行shell,不显示详情

func ShellRt

func ShellRt(c string, showCmd bool) string

ShellRt 执行指令并返回值

func SleepMs

func SleepMs(sec int)

SleepMs 休眠ms秒

func SleepNs

func SleepNs(sec int)

SleepNs 休眠纳秒

func SleepSec

func SleepSec(sec int)

SleepSec 延迟sec秒

func SleepSecCount

func SleepSecCount(sec int)

SleepSecCount 延迟sec秒,倒计时显示

func SleepUs

func SleepUs(sec int)

SleepUs 休眠微秒

func Str2Float

func Str2Float(str string) float64

Str2Float 字符串转int

func Str2Int

func Str2Int(str string) int

Str2Int 字符串转int

func StrSplit

func StrSplit(str string, ls int) (s []string)

StrSplit 字符串按照指定长度分隔到slice里

func StrToIp

func StrToIp(ip string) net.IP

StrToIp 把字符串的IP转换为IP类型

func StrToIpPort

func StrToIpPort(addr string) (ip net.IP, port int)

StrToIpPort 字符串的IP:端口转换为网络格式

func StrToTime

func StrToTime(tStr string) int

StrToTime 字符串转换为时间(layerOut和变换时间应格式相同)

func StrToUdpAddr

func StrToUdpAddr(addr string) (udpAddr *net.UDPAddr)

StrToUdpAddr 字符串的IP:端口转换为网络格式

func StringIpToInt

func StringIpToInt(ipStr string) int

StringIpToInt IP地址转换为int格式

func StructToMap

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

StructToMap 结构体转换为map类型

func Substr

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

Substr 截取字符串 start 起点下标 end 终点下标(不包括)

func TcpCheckTimeout

func TcpCheckTimeout(addr string, timeout ...time.Duration) bool

TcpCheckTimeout 检测端口TCP是否通

func TcpGather

func TcpGather(ip string, ports []string) map[string]string

TcpGather 批量检测端口连通性

func TelnetCheck

func TelnetCheck(url string) bool

TelnetCheck telnet检测端口是否通

func UIntToBytes

func UIntToBytes(n int, b byte) ([]byte, error)

UIntToBytes 整形转换成字节

func Utf8ToGbk

func Utf8ToGbk(src []byte) ([]byte, error)

func ValidateAndOpError

func ValidateAndOpError(s interface{}) (err error, msg string)

ValidateAndOpError 验证字段,如果有误返回错误信息否则返回nil

func WriteBytes

func WriteBytes(filePath string, b []byte) (int, error)

WriteBytes 向文件写入bytes

func WriteString

func WriteString(filePath string, s string) (int, error)

WriteString 向文件写入string

Types

type ComRt

type ComRt struct {
	Code      int         `json:"code"`
	Msg       string      `json:"msg"`
	Ret       interface{} `json:"ret,omitempty"`
	Timestamp int64       `json:"timestamp"`
}

ComRt 通用返回值

func ComRet

func ComRet(code int, msg string, ret map[string]interface{}) ComRt

ComRet 通用返回

func OkRet

func OkRet(msg string, ret map[string]interface{}) ComRt

OkRet 正确返回

func WrongRet

func WrongRet(code int, msg string, ret map[string]interface{}) ComRt

WrongRet 错误返回

type IpRangeAreaSt

type IpRangeAreaSt struct {
	Num      int
	First    net.IP
	Last     net.IP
	FirstInt int
	LastInt  int
}

IpRangeAreaSt 接续出来的Ip范围

func IpTransRange

func IpTransRange(ipArea string) (ipRange IpRangeAreaSt, err error)

IpTransRange 根据IP的CIDR或IP范围,返回第一个和最后一个IP

type MpDb

type MpDb struct {
}

type MyDateSt

type MyDateSt struct {
	TimeUnix10 int //格式化固定时间
	Area       int //时区
}

MyDateSt 时区转换结构体

type MyIpSt

type MyIpSt struct {
	IP        string `json:"ip"`
	Country   string `json:"country"`
	Area      string `json:"area"`
	Province  string `json:"province"`
	City      string `json:"city"`
	Isp       string `json:"isp"`
	Timestamp int    `json:"timestamp"`
}

func GetMyIp

func GetMyIp() (myIp MyIpSt)

GetMyIp 获取本机IP地址及位置

type ReqParamExt

type ReqParamExt struct {
	RgxRules map[string]string //自定义正则
}

ReqParamExt ReqParam函数的拓展参数

type SendMailSt

type SendMailSt struct {
	MailTo   []string //收件人
	Subject  string   //标题
	Body     string   //内容
	MailConn struct {
		User   string
		Passwd string
		Host   string
		Port   int
	}
	Alias  string   //别名
	Attach []string //附件
}

Jump to

Keyboard shortcuts

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