utils

package
v0.0.0-...-88294d8 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2020 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigEnv  = "GVA_CONFIG"
	ConfigFile = "config.yaml"
)
View Source
const (
	B  = 1
	KB = 1024 * B
	MB = 1024 * KB
	GB = 1024 * MB
)

Variables

View Source
var (
	IdVerify               = Rules{"ID": {NotEmpty()}}
	ApiVerify              = Rules{"Path": {NotEmpty()}, "Description": {NotEmpty()}, "ApiGroup": {NotEmpty()}, "Method": {NotEmpty()}}
	MenuVerify             = Rules{"Path": {NotEmpty()}, "ParentId": {NotEmpty()}, "Name": {NotEmpty()}, "Component": {NotEmpty()}, "Sort": {Ge("0")}}
	MenuMetaVerify         = Rules{"Title": {NotEmpty()}}
	LoginVerify            = Rules{"CaptchaId": {NotEmpty()}, "Captcha": {NotEmpty()}, "Username": {NotEmpty()}, "Password": {NotEmpty()}}
	SetUserVerify          = Rules{"ID": {NotEmpty()}, "Username": {NotEmpty()}, "NickName": {NotEmpty()}, "HeaderImg": {NotEmpty()}}
	RegisterVerify         = Rules{"Username": {NotEmpty()}, "NickName": {NotEmpty()}, "Password": {NotEmpty()}, "AuthorityId": {NotEmpty()}}
	PageInfoVerify         = Rules{"Page": {NotEmpty()}, "PageSize": {NotEmpty()}}
	CustomerVerify         = Rules{"CustomerName": {NotEmpty()}, "CustomerPhoneData": {NotEmpty()}}
	AutoCodeVerify         = Rules{"Abbreviation": {NotEmpty()}, "StructName": {NotEmpty()}, "PackageName": {NotEmpty()}, "Fields": {NotEmpty()}}
	WorkFlowVerify         = Rules{"WorkflowNickName": {NotEmpty()}, "WorkflowName": {NotEmpty()}, "WorkflowDescription": {NotEmpty()}, "WorkflowStepInfo": {NotEmpty()}}
	AuthorityVerify        = Rules{"AuthorityId": {NotEmpty()}, "AuthorityName": {NotEmpty()}, "ParentId": {NotEmpty()}}
	DictionaryVerify       = Rules{"Type": {NotEmpty()}, "ID": {NotEmpty()}}
	AuthorityIdVerify      = Rules{"AuthorityId": {NotEmpty()}}
	OldAuthorityVerify     = Rules{"OldAuthorityId": {NotEmpty()}}
	ChangePasswordVerify   = Rules{"Username": {NotEmpty()}, "Password": {NotEmpty()}, "NewPassword": {NotEmpty()}}
	SetUserAuthorityVerify = Rules{"UUID": {NotEmpty()}, "AuthorityId": {NotEmpty()}}
)
View Source
var CustomizeMap = make(map[string]Rules)

Functions

func ArrayToString

func ArrayToString(array []interface{}) string

将数组格式化为字符串

func BreakPointContinue

func BreakPointContinue(content []byte, fileName string, contentNumber int, contentTotal int, fileMd5 string) (error, string)

func CheckMd5

func CheckMd5(content []byte, chunkMd5 string) (CanUpload bool)

func CreateDir

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

func DeleteFile

func DeleteFile(key string) error

func Email

func Email(subject string, body string) error

func EmailTest

func EmailTest(subject string, body string) error

func Eq

func Eq(mark string) string

等于入参(==) 如果为string array Slice则为长度比较 如果是 int uint float 则为数值比较

func ErrorToEmail

func ErrorToEmail(subject string, body string) error

ErrorToEmail Error 发送邮件

func FileMove

func FileMove(src string, dst string) (err error)

FileMove: 文件移动供外部调用 src: 源位置 绝对路径相对路径都可以 dst: 目标位置 绝对路径相对路径都可以 dst 必须为文件夹

func Ge

func Ge(mark string) string

大于等于入参(>=) 如果为string array Slice则为长度比较 如果是 int uint float 则为数值比较

func GetWriteSyncer

func GetWriteSyncer() (zapcore.WriteSyncer, error)

GetWriteSyncer zap logger中加入file-rotatelogs

func Gt

func Gt(mark string) string

大于入参(>) 如果为string array Slice则为长度比较 如果是 int uint float 则为数值比较

func Le

func Le(mark string) string

小于等于入参(<=) 如果为string array Slice则为长度比较 如果是 int uint float 则为数值比较

func Lt

func Lt(mark string) string

小于入参(<) 如果为string array Slice则为长度比较 如果是 int uint float 则为数值比较

func MD5V

func MD5V(str []byte) string

func MakeFile

func MakeFile(fileName string, FileMd5 string) (error, string)

func Ne

func Ne(mark string) string

不等于入参(!=) 如果为string array Slice则为长度比较 如果是 int uint float 则为数值比较

func NotEmpty

func NotEmpty() string

非空 不能为其对应类型的0值

func PathExists

func PathExists(path string) (bool, error)

func RegisterRule

func RegisterRule(key string, rule Rules) (err error)

注册自定义规则方案建议在路由初始化层即注册

func RemoveChunk

func RemoveChunk(FileMd5 string) error

func StructToMap

func StructToMap(obj interface{}) map[string]interface{}

利用反射将结构体转化为map

func UploadFileLocal

func UploadFileLocal(file *multipart.FileHeader) (err error, localPath string, key string)

func UploadRemote

func UploadRemote(file *multipart.FileHeader) (err error, path string, key string)

接收两个参数 一个文件流 一个 bucket 你的七牛云标准空间的名字

func Verify

func Verify(st interface{}, roleMap Rules) (err error)

校验方法 接收两个参数 入参实例,规则map

func ZipFiles

func ZipFiles(filename string, files []string, oldform, newform string) error

Types

type Cpu

type Cpu struct {
	Cpus  []float64 `json:"cpus"`
	Cores int       `json:"cores"`
}

func InitCPU

func InitCPU() (c Cpu, err error)

InitCPU CPU信息

type Disk

type Disk struct {
	UsedMB      int `json:"usedMb"`
	UsedGB      int `json:"usedGb"`
	TotalMB     int `json:"totalMb"`
	TotalGB     int `json:"totalGb"`
	UsedPercent int `json:"usedPercent"`
}

func InitDisk

func InitDisk() (d Disk, err error)

InitDisk 硬盘信息

type Os

type Os struct {
	GOOS         string `json:"goos"`
	NumCPU       int    `json:"numCpu"`
	Compiler     string `json:"compiler"`
	GoVersion    string `json:"goVersion"`
	NumGoroutine int    `json:"numGoroutine"`
}

func InitOS

func InitOS() (o Os)

InitOS OS信息

type Rrm

type Rrm struct {
	UsedMB      int `json:"usedMb"`
	TotalMB     int `json:"totalMb"`
	UsedPercent int `json:"usedPercent"`
}

func InitRAM

func InitRAM() (r Rrm, err error)

InitRAM ARM信息

type Rules

type Rules map[string][]string

type RulesMap

type RulesMap map[string]Rules

type Server

type Server struct {
	Os   Os   `json:"os"`
	Cpu  Cpu  `json:"cpu"`
	Rrm  Rrm  `json:"ram"`
	Disk Disk `json:"disk"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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