utils

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TimeFormat = "2006-01-02 15:04:05"
	Str1Base   = "0123456789QWERTYUIOPASDFGHJKLZXCVBNM"
	Str2Base   = "qwertyuiopasdfghjklzxcvbnm0123456789QWERTYUIOPASDFGHJKLZXCVBNM"
)

Variables

View Source
var (
	Success              = &CodeAndMsg{Code: 200, Message: "成功"}                         // 成功返回
	Fail                 = &CodeAndMsg{Code: 40000, Message: "调用失败"}                     // 调用失败返回
	ParamError           = &CodeAndMsg{Code: 40001, Message: "请求参数错误"}                   // 调用失败返回
	NotAuthed            = &CodeAndMsg{Code: 40002, Message: "没有该操作权限"}                  // 调用失败返回
	NotFoundEnterpriseID = &CodeAndMsg{Code: 40003, Message: "未携带EnterpriseID,无法确认所属企业"} // 调用失败返回
)

Functions

func CheckError

func CheckError(c *gin.Context, err error)

CheckError 检查错误是否是自定义错误类型 并且返回到gin响应中去

func CloseAction

func CloseAction(c io.Closer)

func CreateDirIfNotExist

func CreateDirIfNotExist(path string) error

CreateDirIfNotExist 没有则创建文件夹

func DeleteFile

func DeleteFile(filePath string) error

DeleteFile 文件存在则删除

func GenerateBySourceStr

func GenerateBySourceStr(source string, length int) string

func GeneratePassword

func GeneratePassword(length int) string

func GetBytesForInt64

func GetBytesForInt64(t uint64) []byte

GetBytesForInt64 将int64转为bytes

func GetInt64FromBytes

func GetInt64FromBytes(cn []byte) int64

GetInt64FromBytes 将bytes转为int64

func GetPostData

func GetPostData(r *http.Request) ([]byte, error)

GetPostData 从Post请求中获取数据

func HasDuplicate

func HasDuplicate(arr []*string) bool

HasDuplicate 计算是否有重复的字符串

func IsContainInt64

func IsContainInt64(resource int64, target ...int64) bool

Types

type CodeAndMsg

type CodeAndMsg struct {
	Code    int
	Message string
	// contains filtered or unexported fields
}

func (*CodeAndMsg) AddFormat

func (c *CodeAndMsg) AddFormat(p ...any) *CodeAndMsg

AddFormat 重新赋值占位符

func (*CodeAndMsg) Error

func (c *CodeAndMsg) Error() string

type InfoResult

type InfoResult struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data"`
}

func NewInfoResult

func NewInfoResult(c *CodeAndMsg) *InfoResult

func (*InfoResult) R

func (i *InfoResult) R(c *gin.Context, data any)

R 表示返回响应

type PageUtils

type PageUtils struct {
	Sql        *string // 原搜索sql
	Args       []any   // sql参数
	Total      int64   // 总数
	PageSize   int     // 页大小
	PageNumber int     // 哪一页
	List       any     // 数据
	DB         *sql.DB // 所使用的数据库
}

func (*PageUtils) PageExec

func (p *PageUtils) PageExec(result func(rows *sql.Rows) (any, error)) error

PageExec 传入搜索语句 返回一个PageUtils

Jump to

Keyboard shortcuts

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