util

package
v0.0.0-...-66ce3c7 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2025 License: MIT Imports: 22 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 CreateDir

func CreateDir(dirs ...string) (err error)

CreateDir 批量创建文件夹

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 GetIpAddr

func GetIpAddr() string

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 ParseURL

func ParseURL(str string, component int) (map[string]string, error)

func PathExists

func PathExists(path string) (bool, error)

PathExists 文件目录是否存在

func String2Int

func String2Int(strArr []string) []int

String2Int 将数组的string转int

func SubStr

func SubStr(str string, start int, length ...int) (substr string)

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, ctx *app.RequestContext) (*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 无限极分类

type Zap

type Zap struct {
	Level         string `yaml:"level"`         // 级别
	Prefix        string `yaml:"prefix"`        // 日志前缀
	Format        string `yaml:"format"`        // 输出
	Director      string `yaml:"director"`      // 日志文件夹
	EncodeLevel   string `yaml:"encodeLevel"`   // 编码级
	StacktraceKey string `yaml:"stacktraceKey"` // 栈名
	MaxAge        int    `yaml:"maxAge"`        // 日志留存时间
	ShowLine      bool   `yaml:"showLine"`      // 显示行
	LogInConsole  bool   `yaml:"logInConsole"`  // 输出控制台
}

func (*Zap) TransportLevel

func (z *Zap) TransportLevel() zapcore.Level

TransportLevel 根据字符串转化为 zapcore.Level Author [SliverHorn](https://github.com/SliverHorn)

func (*Zap) ZapEncodeLevel

func (z *Zap) ZapEncodeLevel() zapcore.LevelEncoder

ZapEncodeLevel 根据 EncodeLevel 返回 zapcore.LevelEncoder Author [SliverHorn](https://github.com/SliverHorn)

Directories

Path Synopsis
Package utils provides some utility functions for internal usage.
Package utils provides some utility functions for internal usage.
Package empty provides functions for checking empty/nil variables.
Package empty provides functions for checking empty/nil variables.
encoding
gbinary
Package gbinary provides useful API for handling binary/bytes data.
Package gbinary provides useful API for handling binary/bytes data.
Package gconv implements powerful and convenient converting functionality for any types of variables.
Package gconv implements powerful and convenient converting functionality for any types of variables.
Package gstructs provides functions for struct information retrieving.
Package gstructs provides functions for struct information retrieving.
Package gtag providing tag content storing for struct.
Package gtag providing tag content storing for struct.
Package gtime provides functionality for measuring and displaying time.
Package gtime provides functionality for measuring and displaying time.
Package json provides json operations wrapping ignoring stdlib or third-party lib json.
Package json provides json operations wrapping ignoring stdlib or third-party lib json.
Package reflection provides some reflection functions for internal usage.
Package reflection provides some reflection functions for internal usage.
text
gregex
Package gregex provides high performance API for regular expression functionality.
Package gregex provides high performance API for regular expression functionality.
gstr
Package gstr provides functions for string handling.
Package gstr provides functions for string handling.

Jump to

Keyboard shortcuts

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