utils

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KC_RAND_KIND_NUM   = 0 // 纯数字
	KC_RAND_KIND_LOWER = 1 // 小写字母
	KC_RAND_KIND_UPPER = 2 // 大写字母
	KC_RAND_KIND_ALL   = 3 // 数字、大小写字母
)

Variables

This section is empty.

Functions

func ArrayIntersection

func ArrayIntersection[T any](arrs1, arrs2 []T) []T

ArrayIntersection 取交集

func ArrayKeys

func ArrayKeys(items map[interface{}]interface{}) interface{}

ArrayKeys 获取map里面所有键名

func ArrayToString

func ArrayToString(array []interface{}) string

func Base64Decode

func Base64Decode(encodeStr string) string

Base64Decode base64解码操作

func Base64Encode

func Base64Encode(data string) string

Base64Encode base64编码操作

func CamelString

func CamelString(s string) string

CamelString xx_yy to XxYy

func Contains

func Contains[t any](targets []t, target t) bool

func CopyFile

func CopyFile(srcName, dstName string) (written int64, err error)

CopyFile 拷贝文件

func FirstLower

func FirstLower(s string) string

func FirstUpper

func FirstUpper(s string) string

func GenSn

func GenSn(prefix string) string

GenSn 生成单号

func GenTree

func GenTree(items []map[string]interface{}, addEmptyChild bool, option ...string) []map[string]interface{}

GenTree 将数组map生成tree items 将要排序的数组 addEmptyChild child为空时是否返回空数组,默认true option[0] id别名,默认id option[1] pid别名,默认pid option[2] child别名,默认返回child example:

 items := []map[string]interface{}{
	   {"id": "1", "name": "1"},
	   {"id": "2", "pid": "1", "name": "2"},
	   {"id": "3", "pid": "1", "name": "3"},
	   {"id": "4", "pid": "2", "name": "3"},
  }

JsonEncode(GenTree(items, true))

func GetFuncName

func GetFuncName(i interface{}) string

GetFuncName get function name

func GetIP

func GetIP() (net.IP, error)

GetIP 获取ip

func HmacSha256

func HmacSha256(message string, secret string) string

HmacSha256

func InArray

func InArray(item interface{}, items interface{}) bool

InArray 判断元素是否在数组中 支持string,int,int8,int16,int32,int64,float32,float64,bool类型

func IsDir

func IsDir(path string) bool

IsDir 是否文件夹

func IsEmpty

func IsEmpty(data interface{}) bool

func IsFile

func IsFile(path string) bool

IsFile 是否文件

func IsNumeric

func IsNumeric(item interface{}) bool

IsNumeric 判断是否是数字

func JsonDecode

func JsonDecode(jsonStr string) interface{}

JsonDecode json解码操作 成功返回interface, 失败返回nil

func JsonDecodeTo

func JsonDecodeTo(jsonStr string, dst interface{}) error

JsonDecodeTo json解码操作 失败返回错误,成功返回nil

func JsonEncode

func JsonEncode(data interface{}) string

JsonEncode json编码操作

func KRand

func KRand(size int, kind int) string

KRand 随机字符串

func MD5V

func MD5V(str string) string

func MaheHump

func MaheHump(s string) string

MaheHump 将字符串转换为驼峰命名

func Md5

func Md5(data string, binary ...bool) string

Md5 生成md5字符串, binary为是否设置原始16 字符二进制格式,默认为false

func NewObjectPtr

func NewObjectPtr(i interface{}) interface{}

NewObjectPtr 复制一个对象,返回指针类型的空对象

func ObjectName

func ObjectName(i interface{}) string

ObjectName 获取对象的类型名称

func PasswordEncrypt

func PasswordEncrypt(salt, password string) string

func Pointer

func Pointer[T any](in T) (out *T)

func RandomInt

func RandomInt(min, max int) int

func RandomString

func RandomString(n int) string

随机字符串

func RemoveElements

func RemoveElements[t any](arr []t, targets []t) []t

func RsaDecrypt

func RsaDecrypt(data, privateKey string) (string, error)

RsaDecrypt 私钥解密

func RsaEncrypt

func RsaEncrypt(data, publicKey string) (string, error)

RsaEncrypt 公钥加密

func RsaGenKey

func RsaGenKey(bits int) (privateKey, publicKey []byte, err error)

RsaGenKey 生成私钥/公钥,格式是PKCS#1

func RsaSign

func RsaSign(data, privateKey string, hash crypto.Hash) (string, error)

RsaSign 私钥签名

func RsaVerifySign

func RsaVerifySign(data, sig, publicKey string, hash crypto.Hash) error

RsaVerifySign 公钥验签

func Sha1

func Sha1(data string) string

Sha1

func SnakeString

func SnakeString(s string) string

SnakeString XxYy to xx_yy

func StructToMap

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

func ToInt

func ToInt(arg interface{}) int64

ToInt 转成数字类型 以及浮点四舍五入取整

func ToString

func ToString(args ...interface{}) string

ToString 转成字符串 多个字符串可拼接

func ValidatorCheck

func ValidatorCheck(r *http.Request, req interface{}) error

func VarDump

func VarDump(args ...interface{})

VarDump 打印参数 (没什么用就是想写)

func VerifyChineseName

func VerifyChineseName(name string) bool

func VerifyIDCard

func VerifyIDCard(idCard string) bool

func VerifyTelNum

func VerifyTelNum(name string) bool

Types

type ListReq

type ListReq struct {
	Page     int64  `json:"page,optional,default=1" form:"page,optional,default=1"`
	PageSize int64  `json:"pageSize,optional,default=10" form:"pageSize,optional,default=10"`
	Keyword  string `json:"keyword,optional" form:"pageSize,optional"`
}

type MAP

type MAP map[string]interface{}

Jump to

Keyboard shortcuts

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