Documentation
¶
Index ¶
- Constants
- Variables
- func ArrayIntersection[T any](arrs1, arrs2 []T) []T
- func ArrayKeys(items map[interface{}]interface{}) interface{}
- func ArrayToString(array []interface{}) string
- func Base64Decode(encodeStr string) string
- func Base64Encode(data string) string
- func Base64Md5(params string) string
- func CamelString(s string) string
- func Contains[t any](targets []t, target t) bool
- func CopyFile(srcName, dstName string) (written int64, err error)
- func FirstLower(s string) string
- func FirstUpper(s string) string
- func FormatFileSize(size int64) string
- func GenSn(prefix string) string
- func GenTree(items []map[string]interface{}, addEmptyChild bool, option ...string) []map[string]interface{}
- func GenerateFileName(originalName string) string
- func GeneratePath(prefix, filename string) string
- func GetContentType(filename string) string
- func GetFuncName(i interface{}) string
- func GetIP() (net.IP, error)
- func HmacSha256(message string, secret string) string
- func InArray(item interface{}, items interface{}) bool
- func IsDir(path string) bool
- func IsEmpty(data interface{}) bool
- func IsFile(path string) bool
- func IsNumeric(item interface{}) bool
- func JsonDecode(jsonStr string) interface{}
- func JsonDecodeTo(jsonStr string, dst interface{}) error
- func JsonEncode(data interface{}) string
- func KRand(size int, kind int) string
- func MD5V(str string) string
- func MaheHump(s string) string
- func Md5(data string, binary ...bool) string
- func NewObjectPtr(i interface{}) interface{}
- func ObjectName(i interface{}) string
- func PasswordEncrypt(salt, password string) string
- func Pointer[T any](in T) (out *T)
- func RandomInt(min, max int) int
- func RandomString(n int) string
- func RemoveElements[t any](arr []t, targets []t) []t
- func RsaDecrypt(data, privateKey string) (string, error)
- func RsaEncrypt(data, publicKey string) (string, error)
- func RsaGenKey(bits int) (privateKey, publicKey []byte, err error)
- func RsaSign(data, privateKey string, hash crypto.Hash) (string, error)
- func RsaVerifySign(data, sig, publicKey string, hash crypto.Hash) error
- func Sha1(data string) string
- func SnakeString(s string) string
- func StructToMap(obj interface{}) map[string]interface{}
- func ToInt(arg interface{}) int64
- func ToString(args ...interface{}) string
- func ValidateDocument(file *multipart.FileHeader) error
- func ValidateExcel(file *multipart.FileHeader) error
- func ValidateFile(file *multipart.FileHeader, maxSize int64, allowedExts []string) error
- func ValidateImage(file *multipart.FileHeader) error
- func ValidatorCheck(r *http.Request, req interface{}) error
- func VarDump(args ...interface{})
- func VerifyChineseName(name string) bool
- func VerifyIDCard(idCard string) bool
- func VerifyTelNum(name string) bool
- func WsSendMsg(host string, path string, query string, protocol []string, data []byte) error
- type FileValidator
- type ListReq
- type MAP
Constants ¶
const ( KC_RAND_KIND_NUM = 0 // 纯数字 KC_RAND_KIND_LOWER = 1 // 小写字母 KC_RAND_KIND_UPPER = 2 // 大写字母 KC_RAND_KIND_ALL = 3 // 数字、大小写字母 )
Variables ¶
var DocumentValidator = &FileValidator{ MaxSize: 10 * 1024 * 1024, AllowedExts: []string{".pdf", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".txt"}, AllowedMimes: []string{"application/pdf", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "text/plain"}, ForbiddenExts: []string{".exe", ".bat", ".sh", ".php", ".jsp", ".asp", ".js", ".html", ".htm"}, }
DocumentValidator 文档验证器
var ExcelValidator = &FileValidator{ MaxSize: 10 * 1024 * 1024, AllowedExts: []string{".xls", ".xlsx"}, AllowedMimes: []string{"application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}, ForbiddenExts: []string{".exe", ".bat", ".sh", ".php", ".jsp", ".asp"}, }
ExcelValidator Excel 文件验证器
var ImageValidator = &FileValidator{ MaxSize: 5 * 1024 * 1024, AllowedExts: []string{".jpg", ".jpeg", ".png", ".gif", ".bmp", ".webp"}, AllowedMimes: []string{"image/jpeg", "image/png", "image/gif", "image/bmp", "image/webp"}, ForbiddenExts: []string{".exe", ".bat", ".sh", ".php", ".jsp", ".asp"}, }
ImageValidator 图片验证器
Functions ¶
func ArrayKeys ¶
func ArrayKeys(items map[interface{}]interface{}) interface{}
ArrayKeys 获取map里面所有键名
func ArrayToString ¶
func ArrayToString(array []interface{}) string
func FirstLower ¶
func FirstUpper ¶
func FormatFileSize ¶ added in v0.3.42
FormatFileSize 格式化文件大小
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 GenerateFileName ¶ added in v0.3.42
GenerateFileName 生成文件名(使用MD5 + 时间戳 + 原始扩展名)
func GeneratePath ¶ added in v0.3.42
GeneratePath 生成存储路径(按日期分类) prefix: 路径前缀(如:uploads, images) filename: 文件名 返回:uploads/2024/01/01/filename.jpg
func GetContentType ¶ added in v0.3.42
GetContentType 根据扩展名获取Content-Type
func InArray ¶
func InArray(item interface{}, items interface{}) bool
InArray 判断元素是否在数组中 支持string,int,int8,int16,int32,int64,float32,float64,bool类型
func JsonDecode ¶
func JsonDecode(jsonStr string) interface{}
JsonDecode json解码操作 成功返回interface, 失败返回nil
func JsonDecodeTo ¶
JsonDecodeTo json解码操作 失败返回错误,成功返回nil
func PasswordEncrypt ¶
func RemoveElements ¶
func RemoveElements[t any](arr []t, targets []t) []t
func RsaVerifySign ¶
RsaVerifySign 公钥验签
func StructToMap ¶
func StructToMap(obj interface{}) map[string]interface{}
func ValidateDocument ¶ added in v0.3.42
func ValidateDocument(file *multipart.FileHeader) error
ValidateDocument 验证文档文件
func ValidateExcel ¶ added in v0.3.42
func ValidateExcel(file *multipart.FileHeader) error
ValidateExcel 验证 Excel 文件
func ValidateFile ¶ added in v0.3.42
func ValidateFile(file *multipart.FileHeader, maxSize int64, allowedExts []string) error
ValidateFile 验证上传文件
func ValidateImage ¶ added in v0.3.42
func ValidateImage(file *multipart.FileHeader) error
ValidateImage 验证图片文件
func ValidatorCheck ¶
func VerifyChineseName ¶
func VerifyIDCard ¶
func VerifyTelNum ¶
Types ¶
type FileValidator ¶ added in v0.3.42
type FileValidator struct {
MaxSize int64 // 最大文件大小(字节)
AllowedExts []string // 允许的文件扩展名
AllowedMimes []string // 允许的 MIME 类型
ForbiddenExts []string // 禁止的文件扩展名
}
FileValidator 文件验证器
func (*FileValidator) Validate ¶ added in v0.3.42
func (v *FileValidator) Validate(file *multipart.FileHeader) error
Validate 验证文件