helper

package
v0.0.0-...-8cce4fe Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package helper 助手工具

Index

Constants

View Source
const (
	TopLeft int = iota
	TopRight
	BottomLeft
	BottomRight
	Center
)

水印的位置

Variables

This section is empty.

Functions

func CamelToUnder

func CamelToUnder(str string) string

CamelToUnder 驼峰转下横线

参数:
	str 需要转换的字符串

func GetFileBaseName

func GetFileBaseName(fileName string) string

GetFileBaseName 获取不包含扩展名的文件名称

参数:
	fileName 文件名

func GetFileExt

func GetFileExt(fileName string) string

GetFileExt 获取文件名的扩展名

参数:
	fileName 文件名

func GetRandomString

func GetRandomString(length int) string

GetRandomString 生成图片名字

参数:
	length 需要生成的字符串名字长度

func Img

func Img() *img

Img 获取图像处理实例

func InSlice

func InSlice(item string, items []string) bool

InSlice 判断字符串是否在指定的切片中

参数:
	item 需要判断的字符串
	items 指定的字符串切片

func InterfaceToInt

func InterfaceToInt(val interface{}) int

InterfaceToInt interface类型转换成int

参数:
	val 需要转换的值

func MinusStrList

func MinusStrList(strA, strB []string) []string

MinusStrList 字符串差集

func Page

func Page(tableName string, filterFields []string, db *gorm.DB, ns schema.Namer) *page

Page 获取列表分页实例

参数:
	tableName	模型对应的表名
	db			gorm的DB实例指针
	ns			gorm数据库相关信息接口

func PasswordHash

func PasswordHash(password string) (string, error)

PasswordHash 加密密码

参数:
	password 需要加密的密码

func PasswordVerify

func PasswordVerify(password, hash string) bool

PasswordVerify 验证密码是否正确

参数:
	password 需要验证的密码
	hash 哈希值

func SetString

func SetString(arr []string) []string

SetString 对[]string 类型的切片进行元素唯一化处理

参数:
	arr 需要处理的字符串切片

func SliceRemove

func SliceRemove(slice []string, index int) []string

SliceRemove 删除字符串切片中元素

参数:
	slice 指定的字符串切片
	index 需要删除的切片索引

func StrSliceToMap

func StrSliceToMap(items []string) map[string]struct{}

StrSliceToMap 字符串切片转map

func ToFirstLower

func ToFirstLower(str string) string

ToFirstLower 字符串首字母转小写

参数:
	str 需要转换的字符串

func ToFirstUpper

func ToFirstUpper(str string) string

ToFirstUpper 字符串首字母转大写

参数:
	str 需要转换的字符串

func UnderToCamel

func UnderToCamel(str string) string

UnderToCamel 下横线转驼峰风格

参数:
	str 需要转换的字符串

Types

type DataListParams

type DataListParams struct {
	Data *ListParams `json:"data" form:"data"`
}

DataListParams 列表参数 用data包裹一下

type ListParams

type ListParams struct {
	Keywords   string                 `json:"keywords" form:"keywords"`       //搜索关键字
	OrderField string                 `json:"order_field" form:"order_field"` //列表排序字段
	OrderSort  string                 `json:"order_sort" form:"order_sort"`   //字段排序方式 (desc 倒序, asc升序)
	Page       int                    `json:"page" form:"page"`               //列表当前页码
	PageSize   int                    `json:"page_size" form:"page_size"`     //列表每页显示条数
	Action     string                 `json:"action" form:"action"`           //请求动作
	Filter     map[string]interface{} `json:"filter" form:"filter"`           //精确多字段过滤查询
}

ListParams 列表参数

type ModelFieldOption

type ModelFieldOption struct {
	Value string `json:"value"`
	Label string `json:"label"`
}

ModelFieldOption 存储模型字段选项

func FormatTree

func FormatTree(tree []*ModelFieldOption, db *gorm.DB, tableName string, filter map[string]interface{}, pk string, pid int, label string, pidField string, orderField string, level int) []*ModelFieldOption

FormatTree 格式化下拉树型列表

参数:
	tree map				存储返回的结果
	tableName string        表名
	filter string			过滤条件
	pk string				主键字段名称
	pid int                 父级ID
	label string            标题字段名
	pidField string         父级字段名
	orderField string       排序字段名
	level int               层级数
返回值:map

type Result

type Result struct {
	Data  interface{} `json:"data"`
	Total int64       `json:"total"`
}

result 存放分页列表返回结果

type TreeRes

type TreeRes struct {
	Id    int    //主键值
	Label string //标题
}

TreeRes 存储目录树结果

Jump to

Keyboard shortcuts

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