utils

package
v1.0.1010 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CharsetLower   = "abcdefghijklmnopqrstuvwxyz"
	CharsetUpper   = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	CharsetNumber  = "0123456789"
	CharsetDefault = CharsetLower + CharsetUpper + CharsetNumber
)

Variables

This section is empty.

Functions

func Base64ToImage

func Base64ToImage(base64String, outputPath string) error

Base64ToImage 将Base64编码的数据转换为图片并保存到指定路径

func Base64ToImageWithFormat

func Base64ToImageWithFormat(base64String, outputPath, format string) error

Base64ToImageWithFormat 将Base64编码的数据转换为指定格式的图片并保存

func Compress

func Compress(filePath string) string

Compress 图片压缩

  • @param filePath string 图片路径
  • @return string
  • 压缩图片

func Float64Trans

func Float64Trans(value string) *float64

func GenerateString

func GenerateString(length int) (str string)

GenerateString 生成安全随机字符串

func GetCapitalPass

func GetCapitalPass(val string) string

GetCapitalPass MD5化并转换为大写

func GetFileList

func GetFileList(path string) []string

GetFileList 获取文件列表

  • 根据传入的路径返回该路径下的所有可访问的列表
  • 要求必须将静态文件访问路径定义为static,且静态文件访问目录为resource

func GetImageFormatFromBase64

func GetImageFormatFromBase64(base64String string) string

GetImageFormatFromBase64 从Base64数据中获取图片格式

func InStrArray

func InStrArray(ext string, code int) bool

InStrArray 判断是否在数组中

  • @param ext string 要判断的字符串
  • @param code int
  • 判断是否在字符串数组中

func IntTrans

func IntTrans(value string) *int

func ResAddFile

func ResAddFile(onePath string)

ResAddFile 添加文件到资源包

  • @param onePath string
  • 例:gf pack resource/dist internal/boot/boot_resource.go -n boot
  • 需要在boot中 打包引入 并在main.go中引入boot

func Sha256

func Sha256(src string) string

Sha256 sha256加密

  • @param src string 被加密字符串
  • @return string
  • 将字符串进行hash加密

func StrTrans

func StrTrans(value string) *string

func TimeTrans

func TimeTrans(value string) *gtime.Time

func Transaction

func Transaction(function func() error)

Transaction 简单封装事务操作

Types

type Curd

type Curd[R any] struct {
	Dao  IDao
	Hook gdb.HookHandler
}

func (Curd[R]) All

func (c Curd[R]) All(ctx ctx, where any, order any, with bool) (items []*R, err error)

func (Curd[R]) ArrayField

func (c Curd[R]) ArrayField(ctx ctx, where any, field any) ([]*gvar.Var, error)

func (Curd[R]) BuildMap

func (c Curd[R]) BuildMap(op string, value any, field ...string) map[string]any

func (Curd[R]) BuildWhere

func (c Curd[R]) BuildWhere(req any, changeWhere any, subWhere any, removeFields []string, isSnake ...bool) map[string]any

func (Curd[R]) Builder

func (c Curd[R]) Builder(ctx context.Context) *gdb.WhereBuilder

func (Curd[R]) ClearField

func (c Curd[R]) ClearField(req any, delField []string, subField ...map[string]any) map[string]any

func (Curd[R]) ClearFieldList

func (c Curd[R]) ClearFieldList(ctx ctx, req any, delField []string, where any, order any, with bool) (items []*R, err error)

func (Curd[R]) ClearFieldOne

func (c Curd[R]) ClearFieldOne(ctx ctx, req any, delField []string, where any, order any, with bool) (items *R, err error)

func (Curd[R]) ClearFieldPage

func (c Curd[R]) ClearFieldPage(ctx ctx, req any, delField []string, where any, page *Paginate, order any, with bool) (items []*R, total int, err error)

func (Curd[R]) Count

func (c Curd[R]) Count(ctx ctx, where any) (count int, err error)

func (Curd[R]) DeletePri

func (c Curd[R]) DeletePri(ctx ctx, primaryKey any) error

func (Curd[R]) DeleteWhere

func (c Curd[R]) DeleteWhere(ctx ctx, where any) error

func (Curd[R]) Exists

func (c Curd[R]) Exists(ctx ctx, where any) (exists bool, err error)

func (Curd[R]) FindPri

func (c Curd[R]) FindPri(ctx ctx, primaryKey any, with bool) (model *R, err error)

func (Curd[R]) First

func (c Curd[R]) First(ctx ctx, where any, order any, with bool) (model *R, err error)

func (Curd[R]) Paginate

func (c Curd[R]) Paginate(ctx context.Context, where any, p Paginate, with bool, order any) (items []*R, total int, err error)

func (Curd[R]) Save

func (c Curd[R]) Save(ctx ctx, data any) (id int64, err error)

func (Curd[R]) Sum

func (c Curd[R]) Sum(ctx ctx, where any, field string) (float64, error)

func (Curd[R]) Update

func (c Curd[R]) Update(ctx ctx, where any, data any) (count int64, err error)

func (Curd[R]) UpdatePri

func (c Curd[R]) UpdatePri(ctx ctx, primaryKey any, data any) (count int64, err error)

func (Curd[R]) Value

func (c Curd[R]) Value(ctx ctx, where any, field any) (*gvar.Var, error)

type IDao

type IDao interface {
	DB() gdb.DB
	Table() string
	Group() string
	Ctx(ctx context.Context) *gdb.Model
	Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error)
}

type ListRes

type ListRes[T any] struct {
	Rows  []T
	Total int `json:"total"`
}

func NewListRes

func NewListRes[T any](data []T, total int) *ListRes[T]

type NormalRes

type NormalRes[T any] struct {
	Code int    `json:"code"    dc:"code"`
	Data T      `json:"data"   dc:"data 可null"`
	Msg  string `json:"msg"     dc:"return msg"`
}

func NewNormalRes

func NewNormalRes[T any](data T, msg ...string) *NormalRes[T]

type Paginate

type Paginate struct {
	Limit int `d:"20" json:"limit" v:"max:50"`
	Page  int `d:"1" dc:"页码" json:"page"`
}

type Paginator

type Paginator[I any] struct {
	Items    []I
	Total    int
	IsSimple bool
}

type SClient

type SClient[R any] struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient[R any](request any, url string, header map[string]string) *SClient[R]

func (*SClient[R]) Delete

func (w *SClient[R]) Delete(ctx context.Context) (res *R, err error)

func (*SClient[R]) Get

func (w *SClient[R]) Get(ctx context.Context) (res *R, err error)

func (*SClient[R]) Patch

func (w *SClient[R]) Patch(ctx context.Context) (res *R, err error)

func (*SClient[R]) Post

func (w *SClient[R]) Post(ctx context.Context) (res *R, err error)

func (*SClient[R]) Put

func (w *SClient[R]) Put(ctx context.Context) (res *R, err error)

Jump to

Keyboard shortcuts

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