util

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MaxUploadSize = 10 * 1024 * 1024
	AllowTypes    = []string{"jpg", "jpeg", "png", "svg", "gif", "bmp", "mp3", "mp4", "avi", "pdf", "xls", "xlsx", "ppt", "doc", "docx"}
)

最大上传资源大小是10M

Functions

func FormatToString

func FormatToString(originStr interface{}) string

FormatToString 格式化转化成string

func GenerateBaseSnowId

func GenerateBaseSnowId(num int, n *snowflake.Node) string

GenerateBaseSnowId 生成雪花算法ID

func GeneratePasswordHash

func GeneratePasswordHash(password string, salt string) string

GeneratePasswordHash 生成密码hash值

func GenerateUuid

func GenerateUuid(size int) string

GenerateUuid 生成随机字符串

func GetProjectModuleName

func GetProjectModuleName() string

GetProjectModuleName 获取当前项目的module名称

func GetStructColumnName

func GetStructColumnName(s interface{}, _type int) ([]string, error)

GetStructColumnName 获取结构体中的字段名称 _type: 1: 获取tag字段值 2:获取结构体字段值

func InAnySlice

func InAnySlice[T string | int | int64 | float32 | float64](haystack []T, needle T) bool

InAnySlice 判断某个字符串是否在字符串切片中

func IsPathExist

func IsPathExist(path string) bool

IsPathExist 判断所给路径文件/文件夹是否存在

func MakeFileOrPath

func MakeFileOrPath(path string) bool

MakeFileOrPath 创建文件/文件夹

func MakeMultiDir

func MakeMultiDir(filePath string) error

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

func String2Int

func String2Int(strArr []string) []int

String2Int 将数组的string转int

Types

type FileHeader

type FileHeader struct {
	Filename   string `json:"file_name"`   // 图片新名称
	FileSize   int64  `json:"file_size"`   // 图片大小
	FilePath   string `json:"file_path"`   // 相对路径地址
	OriginName string `json:"origin_name"` // 图片原名称
	MimeType   string `json:"mime_type"`   // 附件mime类型
	Extension  string `json:"extension"`   // 附件后缀名
}

func UploadFile

func UploadFile(path string, r *gin.Context) (*FileHeader, error)

UploadFile 上传图片

type Fn

type Fn func() error

type FormatTime

type FormatTime time.Time

func (FormatTime) MarshalJSON

func (t FormatTime) MarshalJSON() ([]byte, error)

MarshalJSON 实现时间的json序列化

func (*FormatTime) Scan

func (t *FormatTime) Scan(v interface{}) error

Scan implements the Scanner interface

func (*FormatTime) UnmarshalJSON

func (t *FormatTime) UnmarshalJSON(b []byte) error

UnmarshalJSON 反序列化

func (FormatTime) Value

func (t FormatTime) Value() (driver.Value, error)

Value implements the driver Valuer interface

type MyTicker

type MyTicker struct {
	MyTick *time.Ticker
	Runner Fn
}

func NewTicker

func NewTicker(interval int, f Fn) *MyTicker

NewTicker 实例化定时器

func (*MyTicker) Start

func (t *MyTicker) Start()

Start 启动定时器需要执行的任务

type TreeList

type TreeList struct {
	ID        uint64     `json:"id"`
	Pid       uint64     `json:"parent_id"`
	Name      string     `json:"name"`
	IsChecked bool       `json:"is_checked"`
	Children  []TreeList `json:"children"`
}

func GenerateTree

func GenerateTree(list interface{}, pid uint64) []TreeList

GenerateTree 无限极分类

Jump to

Keyboard shortcuts

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