utils

package
v1.7.7 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TextBlack = iota + 30
	TextRed
	TextGreen
	TextYellow
	TextBlue
	TextMagenta
	TextCyan
	TextWhite
)

Variables

This section is empty.

Functions

func Base64ToImage

func Base64ToImage(imageBase64 string) ([]byte, error)

func Black

func Black(msg string) string

func Blue

func Blue(msg string) string

func CheckExist

func CheckExist(src string) bool

CheckExist 检查文件是否存在

func CheckPermission

func CheckPermission(src string) bool

CheckPermission 检查文件权限

func Cyan

func Cyan(msg string) string

func FileCreate

func FileCreate(content bytes.Buffer, name string)

func FileMonitoringById

func FileMonitoringById(ctx context.Context, filePth string, id string, group string, hookfn func(context.Context, string, string, []byte))

func GenerateRandomKey16

func GenerateRandomKey16() string

GenerateRandomKey16 生成16为随机字符串

func GenerateRandomKey20

func GenerateRandomKey20() string

GenerateRandomKey20 生成20位随机字符串

func GenerateRandomKey6

func GenerateRandomKey6() string

GenerateRandomKey6 生成6为随机字符串

func GetCurrentPath

func GetCurrentPath() string

获取当前路径,比如:E:/abc/data/test

func GetCurrentTime

func GetCurrentTime() time.Time

func GetCurrentTimeStamp

func GetCurrentTimeStamp() int64

func GetCurrentTimeStr

func GetCurrentTimeStr() string

func GetDirFiles

func GetDirFiles(dir string) ([]string, error)

func GetExt

func GetExt(fileName string) string

GetExt 获取文件后缀

func GetFileSize

func GetFileSize(filename string) int64

获取文件大小

func GetImgType

func GetImgType(p string) (string, error)

GetImgType 获取Img文件类型

func GetLocaHonst

func GetLocaHonst() string

获取局域网ip地址

func GetLocation

func GetLocation(ip, key string) string

获取外网ip地址

func GetSize

func GetSize(f multipart.File) (int, error)

GetSize 获取文件大小

func GetType

func GetType(p string) (string, error)

GetType 获取文件类型

func GetUUID

func GetUUID() string

func Green

func Green(msg string) string

func Hmac

func Hmac(data string) string

func HttpGetJson added in v1.7.3

func HttpGetJson(url string, param map[string]string, header map[string]string, result interface{}) error

func HttpPostJson added in v1.7.3

func HttpPostJson(url string, param map[string]interface{}, header map[string]string, result interface{}) error

func HttpPostXml added in v1.7.3

func HttpPostXml(url string, param url.Values, header ...map[string]string) ([]byte, error)

func If added in v1.7.4

func If(flag bool, a, b interface{}) interface{}

三目运算?

func IsNotExistMkDir

func IsNotExistMkDir(src string) error

IsNotExistMkDir 检查文件夹是否存在 如果不存在则新建文件夹

func IsStringEmpty

func IsStringEmpty(str string) bool

func Magenta

func Magenta(msg string) string

func MkDir

func MkDir(src string) error

MkDir 新建文件夹

func Open

func Open(name string, flag int, perm os.FileMode) (*os.File, error)

Open 打开文件

func PathCreate

func PathCreate(dir string) error

func PathExist

func PathExist(addr string) bool

PathExist 判断目录是否存在

func PathExists

func PathExists(path string) bool

func Red

func Red(msg string) string

func RemoveRepByMap

func RemoveRepByMap(slc []string) []string

slice去重

func SetColor

func SetColor(msg string, conf, bg, text int) string

func SetPassword

func SetPassword(password string, salt string) (verify string, err error)

SetPassword 根据明文密码和加盐值生成密码

func StringToInt

func StringToInt(e string) (int, error)

func StructToJsonStr

func StructToJsonStr(e interface{}) (string, error)

func Translate

func Translate(form, to interface{})

func White

func White(msg string) string

func Yellow

func Yellow(msg string) string

Types

type APIException

type APIException struct {
	Code      int         `json:"code"`
	Success   bool        `json:"success"`
	Msg       string      `json:"msg"`
	Timestamp int64       `json:"timestamp"`
	Result    interface{} `json:"result"`
}

api结构体

func AuthError

func AuthError(message string) *APIException

授权错误

func NotFound

func NotFound() *APIException

404 错误

func ParameterError

func ParameterError(message string) *APIException

参数错误

func ResponseJson

func ResponseJson(message string, data interface{}, success bool) *APIException

200

func ServerError

func ServerError() *APIException

500 错误处理

func UnknownError

func UnknownError(message string) *APIException

未知错误

func (*APIException) Error

func (e *APIException) Error() string

实现接口

type JSONTime

type JSONTime struct {
	time.Time
}

JSONTime format json time field by myself

func (JSONTime) MarshalJSON

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

MarshalJSON on JSONTime format Time field with %Y-%m-%d %H:%M:%S

func (*JSONTime) Scan

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

Scan valueof time.Time

func (JSONTime) Value

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

Value insert timestamp into mysql need this function.

type ReplaceHelper

type ReplaceHelper struct {
	Root    string //路径
	OldText string //需要替换的文本
	NewText string //新的文本
}

func (*ReplaceHelper) DoWrok

func (h *ReplaceHelper) DoWrok() error

Jump to

Keyboard shortcuts

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