Documentation ¶
Index ¶
- Constants
- Variables
- func ArrFlipInt(s []int) []int
- func ArrayFilter(a []int) (ret []int)
- func ArrayFilterString(a []string) (ret []string)
- func ArrayMergeStr(a []string, b ...[]string) []string
- func ArrayUnique(arr []string) []string
- func Base64Decode(str string) string
- func Base64Encode(str string) string
- func BytesJoin(pBytes ...[]byte) []byte
- func BytesToUInt(b []byte) (int, error)
- func CertFormat(key string, isPub bool) (cert string, err error)
- func CheckAppID(f validator.FieldLevel) bool
- func CheckChar(f validator.FieldLevel) bool
- func CheckCnEnNum(f validator.FieldLevel) bool
- func CheckCnEnNumChar(f validator.FieldLevel) bool
- func CheckEgt0(f validator.FieldLevel) bool
- func CheckEmail(f validator.FieldLevel) bool
- func CheckEmptyString(keys map[string]string) string
- func CheckFloatStr(f validator.FieldLevel) bool
- func CheckInt16(f validator.FieldLevel) bool
- func CheckInt32(f validator.FieldLevel) bool
- func CheckInt64(f validator.FieldLevel) bool
- func CheckIntStr(f validator.FieldLevel) bool
- func CheckKey(f validator.FieldLevel) bool
- func CheckKeys(f validator.FieldLevel) bool
- func CheckKeyword(f validator.FieldLevel) bool
- func CheckMD5(f validator.FieldLevel) bool
- func CheckName(f validator.FieldLevel) bool
- func CheckPassWd(f validator.FieldLevel) bool
- func CheckPhone(f validator.FieldLevel) bool
- func CheckRemark(f validator.FieldLevel) bool
- func CheckRoute(f validator.FieldLevel) bool
- func CheckText(f validator.FieldLevel) bool
- func CheckTrueFalse(f validator.FieldLevel) bool
- func CheckUnionSn(f validator.FieldLevel) bool
- func CheckUrl(f validator.FieldLevel) bool
- func CheckUser(f validator.FieldLevel) bool
- func ChkInt(t string, num int64) bool
- func ChkStr(t string, str string) bool
- func CmdExecWindows(c string, cmdPath string) string
- func CreateDir(p string) bool
- func CreateMultiDir(filePath string) error
- func CreateUUID(up ...interface{}) string
- func DbFunc(dbConfig string) *gorm.DB
- func DeBmUrlStr(key string, str string) string
- func DeStr(pass string, key string) string
- func DebugFunc(isOpen bool, ft func())
- func Die(t ...interface{})
- func Duplicate(a interface{}) (ret []interface{})
- func E(msg string) error
- func Echo(a ...interface{})
- func EchoFail(str string)
- func EchoInfo(str string)
- func EchoPlus(str string, color string, bg string, highLight string)
- func EchoSuccess(str string)
- func EchoWarning(str string)
- func Empty(inStr interface{}) bool
- func EnStr(pass string, key string) string
- func Err(e error)
- func Error(err interface{}, exit bool)
- func ExecCommand(name, sangS string) error
- func ExitGoFunc(done chan int)
- func ExplodeInt(s string, sp string) (its []int)
- func ExplodeStr(s string, sp string) []string
- func FileClear(Path string)
- func FileGetContent(path string) (string, error)
- func FileMd5(path string) (string, error)
- func FilePutContents(Path string, s string, types bool)
- func FileSha256(path string) (string, error)
- func FilterMapEmpty(mp map[string]interface{}, ign []string) map[string]interface{}
- func FilterStr(strs []string) []string
- func GbkToUtf8(src []byte) ([]byte, error)
- func Get(uri string, m map[string]interface{}) (string, error)
- func GetCountryByCode(code string) string
- func GetCountryCode(country string) string
- func GetCpuId() string
- func GetCurrentPath() (string, error)
- func GetExpireTime(sec int) string
- func GetMac() string
- func GetMachineData() string
- func GetMaxProcess()
- func GetPlatformUUID() string
- func GetProcessByCmd(cmd string) (pn *process.Process, e error)
- func GetRandPort() (port int)
- func GetRelativePath() (rootDir string, e error)
- func GetSerialNumber() string
- func GetSn() string
- func GetStringArrayRand(s []string) (r string)
- func GetSysBit() int
- func GetTime10() string
- func GetTime10Int() int
- func GetTime13() string
- func GetTime13Int() int64
- func GormT(dsn string, path string, pacName string) bool
- func GzipCompress(s string) (r string, err error)
- func GzipCompressByte(b []byte) (r string, err error)
- func GzipUnCompress(s string) (result []byte, err error)
- func GzipUnCompressByte(s []byte) (result []byte, err error)
- func Implode(delimiter string, arr []string) string
- func ImplodeInt(delimiter string, arr []int) string
- func InArray(node interface{}, nodes interface{}) bool
- func InArrayInt(node int, nodes []int) bool
- func InArrayStr(one string, arr []string) bool
- func InArrayString(node string, nodes []string) bool
- func InitBaseApi(bm []string, key string, oldSign string) (err error, uri string, sign string)
- func IpIntToString(ipInt int) string
- func IpMaskToInt(netmask string) (int, error)
- func Ipv4MaskString(m []byte) string
- func IsExist(path string) bool
- func IsLanIp(ip string) bool
- func JsonMarshal(st interface{}) []byte
- func JsonOk(c *gin.Context, msg string, ret map[string]interface{}) bool
- func JsonWrong(c *gin.Context, code int, msg string, ret map[string]interface{}) bool
- func KillPid(pid int)
- func KillPidPPid(pid int)
- func KillProcess(name string, exp []int)
- func MapExist(key string, mp map[string]string) bool
- func MapToQuery(m map[string]interface{}) string
- func Md5Byte(b []byte) (m []byte)
- func Md5Lower(str string) string
- func Md5Upper(str string) string
- func MdDecode(str string, key string, expSec int) string
- func MdEncode(str string, key string, expSec int) string
- func MdXor(str, key string) string
- func MtRand(min, max int) int
- func MyDate(Format interface{}, mds ...MyDateSt) string
- func Now() int
- func OpenTrans()
- func ParseInt(s string) int
- func ParseIpv4(ip string) (string, int)
- func PathJoin(p ...string) string
- func Pln(a ...interface{})
- func Post(uri string, m interface{}) (string, error)
- func PostTimeout(uri string, m interface{}, timeout time.Duration) (string, error)
- func ProcessId() (pid []int32)
- func ProcessName() (name []string)
- func RandStr(k string, n int) string
- func RedisFunc(addr string, port int, password string, index int) *redis.Client
- func RegValidate()
- func RemoveAll(p string) bool
- func ReqParam(ctx *gin.Context, method string, p interface{}, rpe ...ReqParamExt) (b map[string]string, e error)
- func ReturnDetailProcess(content string) (pidI []int)
- func Rsa2Private(str string, key string, encode bool) (rs string, e error)
- func Rsa2Public(str string, key string, encode bool) (rs string, e error)
- func SendMail(d SendMailSt) error
- func ShellExec(c string, cmdShow bool, runtimeShow bool) string
- func ShellExecEcho(c string) string
- func ShellExecEchoDisable(c string) string
- func ShellRt(c string, showCmd bool) string
- func SleepMs(sec int)
- func SleepNs(sec int)
- func SleepSec(sec int)
- func SleepSecCount(sec int)
- func SleepUs(sec int)
- func Str2Float(str string) float64
- func Str2Int(str string) int
- func StrSplit(str string, ls int) (s []string)
- func StrToIp(ip string) net.IP
- func StrToIpPort(addr string) (ip net.IP, port int)
- func StrToTime(tStr string) int
- func StrToUdpAddr(addr string) (udpAddr *net.UDPAddr)
- func StringIpToInt(ipStr string) int
- func StructToMap(obj interface{}) map[string]interface{}
- func Substr(str string, start int, end int) string
- func TcpCheckTimeout(addr string, timeout ...time.Duration) bool
- func TcpGather(ip string, ports []string) map[string]string
- func TelnetCheck(url string) bool
- func UIntToBytes(n int, b byte) ([]byte, error)
- func Utf8ToGbk(src []byte) ([]byte, error)
- func ValidateAndOpError(s interface{}) (err error, msg string)
- func WriteBytes(filePath string, b []byte) (int, error)
- func WriteString(filePath string, s string) (int, error)
- type ComRt
- type IpRangeAreaSt
- type MpDb
- type MyDateSt
- type MyIpSt
- type ReqParamExt
- type SendMailSt
Constants ¶
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 ¶
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 正则表达式
var Validate = validator.New()
Validate 创建校验器
Functions ¶
func ArrayFilterString ¶
ArrayFilterString 删除string数组里的空值
func ArrayMergeStr ¶
ArrayMergeStr 合并string数组
func CheckCnEnNumChar ¶
func CheckCnEnNumChar(f validator.FieldLevel) bool
CheckCnEnNumChar 中英文数字常见字符
func CheckEmptyString ¶
CheckEmptyString 返回map里为空的键,逗号分隔
func CreateMultiDir ¶
CreateMultiDir 调用os.MkdirAll递归创建文件夹
func Echo ¶
func Echo(a ...interface{})
func FilePutContents ¶
FilePutContents 写入文件,type=true覆盖,type=false追加
func FilterMapEmpty ¶
FilterMapEmpty 过滤为空的map和忽略的map,保留不为空和忽略字段
func GetProcessByCmd ¶
GetProcessByCmd 根据cmd命令获取对应的pid
func GetStringArrayRand ¶
GetStringArrayRand 随机获取字符串数组中的一个值返回
func GzipCompressByte ¶
GzipCompressByte GZIP压缩字符串 OK
func GzipUnCompress ¶
GzipUnCompress GZIP解压缩字符串 OK
func GzipUnCompressByte ¶
GzipUnCompressByte GZIP解压缩字符串 OK
func InArrayString ¶
InArrayString 判断是否在数组里 string
func InitBaseApi ¶
InitBaseApi 初始化获取域名
func JsonOk ¶
JsonOk gin版本返回
func JsonWrong ¶
JsonWrong gin版本返回
func MdDecode ¶
MdDecode 梦蝶跨平台解密算法,expSec密钥有效期(秒) OK
func MdEncode ¶
MdEncode 梦蝶跨平台加密算法,expSec密钥过期时间(秒) OK
func PostTimeout ¶
PostTimeout POST请求带超时设置
func RedisFunc ¶
RedisFunc 初始化redis数据库
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 ¶
ReturnDetailProcess 杀死详细进程,返回pid的int类型数组
func Rsa2Private ¶
Rsa2Private RSA2私钥加解密 OK
func Rsa2Public ¶
Rsa2Public RSA2公钥加解密 OK
func ShellExec ¶
ShellExec 执行shell,同步
func ShellExecEchoDisable ¶
ShellExecEchoDisable 执行shell,不显示详情
func StrToUdpAddr ¶
StrToUdpAddr 字符串的IP:端口转换为网络格式
func Substr ¶
Substr 截取字符串 start 起点下标 end 终点下标(不包括)
func TcpCheckTimeout ¶
TcpCheckTimeout 检测端口TCP是否通
func ValidateAndOpError ¶
ValidateAndOpError 验证字段,如果有误返回错误信息否则返回nil
Types ¶
type ComRt ¶
type ComRt struct { Code int `json:"code"` Msg string `json:"msg"` Ret interface{} `json:"ret,omitempty"` Timestamp int64 `json:"timestamp"` }
ComRt 通用返回值
type IpRangeAreaSt ¶
IpRangeAreaSt 接续出来的Ip范围
func IpTransRange ¶
func IpTransRange(ipArea string) (ipRange IpRangeAreaSt, err error)
IpTransRange 根据IP的CIDR或IP范围,返回第一个和最后一个IP
type MpDb ¶
type MpDb struct { }
type MyIpSt ¶
type ReqParamExt ¶
ReqParamExt ReqParam函数的拓展参数